処理が継続されるエラー発生時に例外を投げるというもの。エラー処理を例外で統一させる事が出来る。
class IOException extends Exception {} function errorHandler($errno, $errstr, $errfile, $errline) { if (false !== substr('failed to open stream', $errstr)) { throw new IOException($errstr, $errno); } throw new Exception($errstr, $errno); } set_error_handler('errorHandler'); try { file_put_contents('cosmos:\\1.txt', 'asdf'); } catch (IOException $e) { echo 'IO exception: ' . $e->getMessage(); } catch (Exception $e) { echo 'Unknown exception: ' . $e->getMessage(); }PHP coding tip: Convert notices and warnings into Exceptions
