Handling errors inside shutdown functions

Using register_shutdown_function() to do stuff on script shutdown requires special error handling. Normal error handling does not work within the function called, so if an error occurs inside your shutdown function you get this nondescript error:

Fatal error: Exception thrown without a stack frame in Unknown on line 0

The solution was to catch the exception and call the exception handler directly:

function shutdown_handler() {

	try {
		//... do stuff
	catch(Exception $e) {

Written on July 14, 2009