rubing Posted March 8, 2008 Share Posted March 8, 2008 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 More sharing options...
rubing Posted March 9, 2008 Author Share Posted March 9, 2008 Well, I forgot to mention that you can set up a custion exception handler for unhandled exceptions. But still why would anyone want to re-throw an exception, instead of just handling it. I just don't get it! Link to comment https://forums.phpfreaks.com/topic/95135-rethrowing-exceptions/#findComment-487806 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.