0
Exception handling in C++
In my below code, why doesn't the catch block catch my "int" exception? https://code.sololearn.com/cphMlBbGvbLj/?ref=app
4 Antworten
+ 2
Rishi When throwing an Exception, it can either be caught by a catch block in the same immediate scope, thrown up the stack trace to the calling function until caught by a catch block, or finally thrown out of the main function to the operating system to be handled. The last of which cannot be caught and is what you're doing in your code.
+ 2
Rishi you don't, or can't. If a part of your code might throw exception, you wrap it with try and handle it. If you guarantee that your code doesn't throw exception, you don't wrap it with try.
+ 1
Because it is prior to the try block and out of its scope. Move it into the body of the try block and it will be caught.
0
ChaoticDawg yes it works, but how to catch the throw statements which are outside the try block?