Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does "throw;" outside a catch block do?

Tags:

People also ask

What does throw in catch block do?

Re-throwing exceptions When an exception is cached in a catch block, you can re-throw it using the throw keyword (which is used to throw the exception objects).

What happens if an exception is thrown outside a catch block?

If a catch block ends normally, without a throw , the flow of control passes over all other catch blocks associated with the try block. Whenever an exception is thrown and caught, and control is returned outside of the function that threw the exception, stack unwinding takes place.

Is it good practice to throw exception in catch block?

It's fine practice to throw in the catch block. It's questionable practice to do so ignoring the original exception.

What happens if you throw in a catch?

It's passing the exception up to the next handler. If there is a try... catch block around the method call in which the exception is caught and thrown, it will be picked up and processed by that handler instead.


I just stumbled this code:

void somefunction() {    throw; } 

and I wonder: what does it mean?