C #: throws out the exit from the current function?

If there is a throw statement in the middle of the function, does the function execute at that point?

+7
source share
7 answers

Yes, with the exception of any finally blocks, or if the function has an exception handler that can catch the type of exception you are throwing.

+13
source

The control moves on to the next exception catch ( catch block) in the call stack, whether it be the current method or one of its parents. If throw not encapsulated in a try / catch block, any finally blocks are executed before the parent catch block is requested.

+5
source

Have you tried? :)

I think the correct answer is, it depends. If you wrapped the throw with try / catch for some strange reason, then no. If you haven’t done so, then yes, unless you have caught an exception somewhere in the call stack, in which case your entire application will crash.

+1
source

Yes, if you don't catch it or get the final block:

 try { var foo = 42 /0; } finally { // This will execute after the exception has been thrown } 
+1
source

Yes Yes. It throws an exception that rises above the calling stack.

0
source

Yes. It will jump to the nearest catch .

0
source

An exception is an event that occurred when it was not intended, and therefore the application does not know what to do with such an event. In all OOP languages ​​(what I know), what happens at runtime is to stop the function that triggered the event, and then throw the exception on the stack until someone knows what to do with it. This is where try / catch blocks come in.

0
source

All Articles