Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
1.57/5 (4 votes)
See more:
I want to know when will the removal of try catch block leads to core dump
Posted
Comments
PIEBALDconsult 25-Nov-15 9:46am    
Not always.

1 solution

Not exactly. To answer this question, you need to understand how exception works. The key to understanding is this: they propagate back to stack. To understand that, you also need to understand how the regular call stack works (not to be mixed up with exception stack built on top of the stack mechanism), this is what all the call-return system is based on, as well local variables and passing function parameters.

Structural exception handling acts as a kind of "time machine". I tried to explain it here:
Does Exception in C# Constructor Cause Caller Assignment to Fail?[^],
where was stored .net exceptions in operating system[^].

Now, what happens if you never handle exceptions up to the top stack frame of some thread, or if you handle only some of them? It depends on what thread is that. Consider the main thread. The exceptions propagate up and up the stack, until the propagation jumps to some runtime component which ultimately called your entry point, main function. Then it depends on what this component does. It may produce the dump. Or not. For other threads, the thread just terminates. The handling of unhandled exceptions may or may not happen. Normally, it doesn't happen, unless some runtime mechanism reserved some handling on top of threading mechanism.

All the scenarios explained above are abnormal. First of all, you should handle exceptions as little as possible, avoid handling them too locally. You have to do it only in special points I call "competency points". At the same time, you have to ultimately catch all exceptions somewhere on the top stack frame of each thread. UI threads usually need handling on top stack frame of the biggest event-driven loop and recover from exceptions to continue the loop in all cases. UI library usually have predefined mechanism for that.

Se also my past answers:
Image taken from Webcam not getting saved on the server[^],
Unhandled Exception : Access Violation[^],
How do I catch native c++ exception in managed c++ class?[^],
When i run an application an exception is caught how to handle this?[^].

Some of my answers I referenced are about .NET. Don't be confused with that: it just doesn't matter, all my considerations are also applicable to C++, or almost anything else.

—SA
 
Share this answer
 
v3
Comments
Member 12018498 27-Nov-15 0:25am    
Thank you so much Alex. really its 5++ answer :)
Sergey Alexandrovich Kryukov 27-Nov-15 1:00am    
Thank you for your acceptance of the answer and voting, but... who are you talking to? No part of my name corresponds to "Alex"...
—SA
Member 12018498 27-Nov-15 4:33am    
Sorry.. I mean Sergey Alexandrovich --SA
Sergey Alexandrovich Kryukov 27-Nov-15 17:32pm    
:-)
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900