Where is the resumption of execution after an exception?

In general, where does program execution resume after an exception has been caught and caught? Does it continue after the line of code in which the exception was thrown, or does it resume after it is detected? Also, is this behavior compatible in most programming languages?

+3
source share
5 answers

execution resumes when an exception is caught, that is, at the beginning of a block catchthat specifically addresses the current type of exception. the catch block is executed, other catch blocks are ignored (think of a multiple block catchas a switch statement). in some languages, a block finallycan also be executed after catch. then the program will continue the next command after all try ... catch ... finally ....

you should notice that if the exception does not fall into the block, the exception extends to the calling function of the current function and up to the call stack until catchit throws the exception. in this case, you can think of function calls, such as a macro: insert the code of each function where it is called, and you will clearly see the attachment of all the blocks try .. catch ... finally ....

, . ( ).

, . try ... catch ... finally ...: finally , finally a catch ( try 2), (catch (...) ++), .

+3

catch, catch.

+7

catch ( ).
, .

( ++)
, , , ( ). , RAII.

+2

Bjarne Stroustrup " ", , - . , . , - , , , . - ( - , ), .

, ++ , , catch , .

+2

It resumes when an exception is caught. Otherwise, what's the point of writing an exception clause?

+1
source

Source: https://habr.com/ru/post/1726582/


All Articles