Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what happens when two exceptions occur?

what will the program behave when they have two exceptions. And none of them have been caught yet. what type of handler will be called . lets say both the exceptions were of different type. i apologize if i am not clear but i feel i have made myself clear enough. thank you!!!

what if the try block throws an exception and try block is exited which destroyes all the automatic variables.Lets say one was an automatic object and its destructor again threw an exception.Now we have two uncaught exception.My question is based on this fact. thank you!!

like image 353
Ashish Yadav Avatar asked Mar 13 '10 20:03

Ashish Yadav


2 Answers

It depends entirely on the language. However, in all the languages I know there can't ever be multiple exceptions at the same time (in the same thread). If an exception has been thrown, it travels up the call stack until it's caught, with no code executing during this time. If the exception is not caught, the program crashes before another can be thrown. If it is caught, the exception is no longer "active" and if the handler throws a new exception, the old one is forgotten.

like image 92
Max Shawabkeh Avatar answered Sep 29 '22 06:09

Max Shawabkeh


At the CPU level (on x86), there is a situation called a double fault:

On the x86 architecture, a double fault exception occurs if the processor encounters a problem while trying to service a pending interrupt or exception.

However, this kind of "double fault" is a very low level situation and is only of concern to the operating system kernel.

like image 22
Greg Hewgill Avatar answered Sep 29 '22 06:09

Greg Hewgill