Skip to main content
311 votes
11 answers
197k views

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 ...
Seibar's user avatar
  • 70.7k
144 votes
5 answers
94k views

Will the following append() in the catch cause the rethrown exception to see the effect of append() being called? try { mayThrowMyErr(); } catch (myErr &err) { err.append("Add to my message ...
WilliamKF's user avatar
  • 43.7k
113 votes
2 answers
27k views

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 ...
Ahmad F's user avatar
  • 31.8k
67 votes
3 answers
104k views

I'm learning to use python. I just came across this article: http://nedbatchelder.com/blog/200711/rethrowing_exceptions_in_python.html It describes rethrowing exceptions in python, like this: try: ...
Bosiwow's user avatar
  • 2,263
43 votes
12 answers
8k views

I rethrow an exception with "throw;", but the stacktrace is incorrect: static void Main(string[] args) { try { try { throw new Exception("Test"); //Line 12 } ...
Floyd's user avatar
  • 1,928
27 votes
3 answers
12k views

Consider the following C++ code: try { throw foo(1); } catch (foo &err) { throw bar(2); } catch (bar &err) { // Will throw of bar(2) be caught here? } I would expect the answer is no ...
WilliamKF's user avatar
  • 43.7k
20 votes
6 answers
7k views

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 ...
orandov's user avatar
  • 3,306
16 votes
4 answers
6k views

In my onCreate() I set an UncaughtException handler as follows: Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(...
Eternal Learner's user avatar
10 votes
5 answers
4k views

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 :...
Pragmateek's user avatar
  • 13.6k
10 votes
2 answers
14k views

I am trying to create a helper method that will eliminate the need of having code like this: void foo() throws ExceptionA, ExceptionB, DefaultException { try { doSomething(); // that throws ...
gsf's user avatar
  • 7,512
9 votes
3 answers
7k views

I have a wrapper responsible for logging operations, named OperationWrapper. Its structure is simple and as follows: public void runOperation(Operation o) throws Exception{ logOperationStarted()...
Shahar's user avatar
  • 488
7 votes
6 answers
22k views

try { // code which throws exception. } catch (SQLException sqlex) { logger.error("Custom message", sqlex); **throw new CustomApplicationException("Custom message", sqlex);** } In the ...
user613114's user avatar
  • 2,851
6 votes
1 answer
465 views

As far as I understand, rethrows essentially creates two functions from a single declaration/definition, like so: func f(_ c: () throws -> Void) rethrows { try c()} // has the same effect as ...
Alexander's user avatar
  • 64k
6 votes
1 answer
236 views

When running the following code, I see the memory consumption of the process grow. Is there a memory leak in my code, is there a memory leak in the std implementation, or is it intended behaviour? It'...
Philipp B.'s user avatar
6 votes
2 answers
387 views

The more precise rethrow allows to write code that throws the exception really thrown : public void foo(String bar) throws FirstException, SecondException { try{ // Code that may throw ...
Julien's user avatar
  • 1,338

15 30 50 per page
1
2 3 4 5