8 questions
311
votes
11
answers
197k
views
Best practices for catching and re-throwing .NET exceptions
What are the best practices to consider when catching exceptions and re-throwing them? I want to make sure that the Exception object's InnerException and stack trace are preserved. Is there a ...
43
votes
12
answers
8k
views
Incorrect stacktrace by rethrow
I rethrow an exception with "throw;", but the stacktrace is incorrect:
static void Main(string[] args) {
try {
try {
throw new Exception("Test"); //Line 12
}
...
113
votes
2
answers
27k
views
What are the differences between throws and rethrows in Swift?
After searching for some references to figure it out, -unfortunately- I could not find useful -and simple- description about understanding the differences between throws and rethrows. It is kind of ...
20
votes
6
answers
7k
views
Why does resharper say 'Catch clause with single 'throw' statement is redundant'?
I thought throwing an exception is good practice to let it bubble back up to the UI or somewhere where you log the exception and notify the user about it.
Why does resharper say it is redundant?
try
...
16
votes
4
answers
6k
views
How to re-throw an exception
In my onCreate() I set an UncaughtException handler as follows:
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(...
10
votes
5
answers
4k
views
Throw VS rethrow : same result?
refering to a lot of documentation on the net, particularly on SO, eg : What is the proper way to re-throw an exception in C#?
there should be a difference between "throw e;" and "throw;".
But, from :...
5
votes
1
answer
2k
views
Why do "throw" and "throw ex" have the same behavior in this case?
I'm flabbergasted. I always thought that throw by itself in a catch block would throw the exception at hand without altering the stack trace, but that throw ex in a catch block would alter the stack ...
1
vote
1
answer
1k
views
How to catch a base class constructor's exception in C++?
I have a class that is derived from another class. I want to be able to catch and re-throw the exception(s) thrown by the derived class's constructor in my derived class's constructor.
There seems to ...