Jump to content

rethrowing exceptions


rubing

Recommended Posts

I have been reading that it is common to rethrow exceptions in catch blocks.  Why would one want to do this.  Wouldn't that just leave you with an unhandled exception.  For example:

 

$variable = NULL;

try
{
  $variable = some_kind_function();
  another_crazy_function($variable);
}
catch (Exception $e)
{
failure causes clean-up and rethrow
if ($variable != NULL)
  close_function($variable);
throw $e;  //WHY RETHROW???
}

//rest of script ...
close_function($variable);

 

Link to comment
https://forums.phpfreaks.com/topic/95135-rethrowing-exceptions/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.