Tagged Questions
8
votes
5answers
349 views
Saving a contact and dealing with exceptions
try{save.Username = usernamedetails.Rows[0].ItemArray[0].ToString(); }
catch{ save.Username = ""; }
try { save.Firstname = dtdetails.Rows[0].ItemArray[1].ToString(); }
catch { save.Firstname = ""; }
...
6
votes
2answers
298 views
Simplifying exception handling on Enumerators
I have a files search function that iterates over a given directory until a given depth is reached and returns the found files. I did this via the Enumerate methods of the Directory class and yield ...
5
votes
6answers
2k views
Could this ExecuteScalar call be written better?
I came across this code in our project today. Where possible I'm trying to leave the code base in a better shape than I found it, as I go along, and this method jumped out at me for a number of ...
4
votes
2answers
157 views
I there a better way to handle try in C#
I know that is generally expected that you should not swallow exceptions. In this code an Infragistic's UltraWinGrid is being configured. Is there a better way to handle the failed catch's are is this ...
4
votes
3answers
120 views
Wrapping Exceptions
It doesn't happen often, but I sometimes come across cases where I miss Java's checked exceptions, especially in medium sized methods of about 30 odd lines that call outward. Often, the following ...
4
votes
2answers
2k views
Recommended method to use a WCF service client and handling it's exceptions
I am new to WCF and need to work with another programmer's code.
I am unsure of the way the WCF service client is used here :
private void barButtonDocuments_ItemClick(object sender, ...
4
votes
3answers
185 views
Handling optimistic concurrency violations
I'm trying to establish a concurrency violation verification in my SQL updates using C# and raw SQL.
What I'm doing now is storing the TimeStamp value in a byte[] upon selection and before updating ...
4
votes
1answer
144 views
Is there a better way to test for the exception conditions?
This method assigns the value of a specified column in a DataRow to specified property in an object.
I have 3 conditionals handling exceptions, and I want these conditions to throw exceptions.
The ...
3
votes
2answers
236 views
Is this right way to implement Abort, Retry and Ignore activity pattern?
I've a bunch of sequential activities. These are long running. Once an activity is complete, it can't be rolled back. Now something deep down the line fails. Now I've few options
Report this to end ...
3
votes
2answers
114 views
Tasks: exceptions and cancelation
I need to do a long running task. I've done this by executing a Task while there's a loading box on the UI. When an exception is thrown, I want to stop the task and show a msgbox to the user. If ...
3
votes
2answers
121 views
Is my error handling feasible when dealing items not found in an array?
internal void ShiftSwapInstrument(SwapCurve shiftedCurve, string swapToShift)
{
if (SwapExists(shiftedCurve, swapToShift))
{
var rateToShift = shiftedCurve.Swaps.Single(r => ...
3
votes
2answers
544 views
Encapsulating common Try-Catch code. Is this a known pattern? Is it good or bad?
In an effort to reduce code duplication, I often use and have used this style to capture handling of exceptions on a boundary of an application:
Given the following extension methods:
public static ...
2
votes
2answers
332 views
Open database and hande errors
How to make this code better?
if (Program.Data.DataBase.TryOpenDataBase())
{
bool result;
DataBase= new Program.Data.DataBase(out result);
if (!result)
{
if (Program.DataBase!= null)
...
2
votes
1answer
175 views
Is This a Sufficient Demonstration of the Effects of Exception Handling
We have some developers in house that believe it is best practice to use exception handing as flow control, as well as, thinking that catching and re-throwing exceptions is effective error handling.
...
1
vote
1answer
143 views
Functional Exception handling with TryCatchFinally Statement helpers
Hello All, I wrote something to the effect of a try catch finally statement helper in functional style so that I can shorten much of the code I'm writing for my Service Layer that connects to a sql ...