0

Can someone explain better exception?

I don't understand the use of try: is it mandatory to use throw and catch in a try block? And what if we throw an exception which is caught later, all the instructions between those blocks are ignored? And what happens if an exception isn't caught?

21st Jul 2016, 5:40 PM
Aceitunarabe
Aceitunarabe - avatar
9 odpowiedzi
+ 2
"throw" is the keyword you use to transfer an exception instance to the exception handling system in the background. try/catch belongs together and formulate "try this code block in which an exception may occur and if it does immediately leave the try block and attempt to fit the type of the exception to the first catch clause that fits" (superclasses are a fit). If there is none, end this function immediately and pass the exception to the caller of this function. Begin handling the exception in this function.
21st Jul 2016, 6:00 PM
Stefan
Stefan - avatar
+ 2
Jop, the modification will be in memory. Nevertheless, pls note that stack unwinding takes place, if the exception is not caught, i.e. the current function is ended at the place the exception occurred, then the handling system goes to the caller, does the same, if the exception is not called until the main function is ended... That is *stack unwinding*.
21st Jul 2016, 6:37 PM
Stefan
Stefan - avatar
0
Okay thanks, it's much clearer than SoloLearn course imo ^^
21st Jul 2016, 6:04 PM
Aceitunarabe
Aceitunarabe - avatar
0
Kk, thx. It's not that difficult, actually. Have a fun time :-)
21st Jul 2016, 6:12 PM
Stefan
Stefan - avatar
0
Yes but a good explanation is still needed although it's not that difficult ;) Thx again :)
21st Jul 2016, 6:13 PM
Aceitunarabe
Aceitunarabe - avatar
0
One last thing, will instructions that have been executed in a try block before an exception is raised, be kept in memory? For example if we modified a variable, will this modification be maintained?
21st Jul 2016, 6:32 PM
Aceitunarabe
Aceitunarabe - avatar
0
Ok for the unwinding part, but I didn't understood the answer, it will or won't be kept in memory? ^^
21st Jul 2016, 6:49 PM
Aceitunarabe
Aceitunarabe - avatar