Linked Questions
42 questions linked to/from Best practices for catching and re-throwing .NET exceptions
556 votes
9 answers
252k views
What is the proper way to rethrow an exception in C#? [duplicate]
Is it better to do this: try { ... } catch (Exception ex) { ... throw; } Or this: try { ... } catch (Exception ex) { ... throw ex; } Do they do the same thing? Is one better ...
26 votes
8 answers
37k views
What is the right way to pass on an exception? (C#) [duplicate]
I'm wondering what the correct way is to pass on an exception from one method to another. I'm working on a project that is divided into Presentation (web), Business and Logic layers, and errors (e.g. ...
0 votes
4 answers
180 views
Are these 2 try/catch/throw statements the same? [duplicate]
Given the following statements: try { ... some code ... } catch { ... some cleanup code ... throw; } and try { ... some code ... } catch (Exception ex) { ... some cleanup code ......
-2 votes
2 answers
850 views
How to log an exception and rethrow as the actual type [duplicate]
I have a query handler decorator which logs any exceptions: public class QueryHandlerLogDecorator<TQuery, TResult> : IQueryHandler<TQuery, TResult> where TQuery : IQuery<TResult>...
-1 votes
1 answer
115 views
Best practice for caught exceptions not being used [duplicate]
I'm curious to find out what the best practice is for caught exceptions that aren't used. The irony is that this is going against best practice in the first place. I've found myself in a position to ...
0 votes
1 answer
193 views
Is there a way to stop running SQL scripts if we get an error? [duplicate]
I am developing a program for my final project of college that consists of taking several SQL scripts from a fixed folder and executing them. In a meeting with my project supervisor he said that it ...
0 votes
1 answer
142 views
throw; throw ex; optimal [duplicate]
Possible Duplicate: .NET - Throwing Exceptions best practices Hi, I have seen people re-throwing exceptions as given below. which one is optimal? Why one mechanism is optimal than the other one. ...
0 votes
0 answers
35 views
How to throw exeption from some method using c# [duplicate]
What are key words from throw exeption like this? public void methodOne() throw SomeExeption { try{ doSomething(); catch(SomeExeption se) { throw se; } } public void ...
374 votes
12 answers
115k views
How to rethrow InnerException without losing stack trace in C#?
I am calling, through reflection, a method which may cause an exception. How can I pass the exception to my caller without the wrapper reflection puts around it? I am rethrowing the InnerException, ...
215 votes
15 answers
377k views
How using try catch for exception handling is best practice
while maintaining my colleague's code from even someone who claims to be a senior developer, I often see the following code: try { //do something } catch { //Do nothing } or sometimes they write ...
230 votes
13 answers
330k views
Difference between 'throw' and 'throw new Exception()'
What is the difference between try { ... } catch{ throw } and try{ ... } catch(Exception e) {throw new Exception(e.message) } regardless that the second shows a message.
32 votes
5 answers
37k views
How to throw exception without resetting stack trace?
This is a follow-up question to Is there a difference between “throw” and “throw ex”? is there a way to extract a new error handling method without resetting the stack trace? [EDIT] I will be trying ...
10 votes
11 answers
25k views
Repeating a function in C# until it no longer throws an exception
I've got a class that calls a SOAP interface, and gets an array of data back. However, if this request times out, it throws an exception. This is good. However, I want my program to attempt to make ...
24 votes
5 answers
29k views
exception with no stack trace - how?
We have a service which will log unhandled exceptions at the app domain level (via Log4net). We logged: 2014-01-28 16:49:19,636 ERROR [49] FeedWrapperService - unhandled System....
17 votes
5 answers
56k views
Throw exception from Called function to the Caller Function's Catch Block
internal static string ReadCSVFile(string filePath) { try { ... ... } catch(FileNotFoundException ex) { throw ex; } catch(Exception ex) { ...