note 82197 added to language.exceptions

From: Date: Mon, 31 Mar 2008 17:55:37 +0000
Subject: note 82197 added to language.exceptions
Groups: php.notes 
Request: Send a blank email to php-notes+get-137795@lists.php.net to get a copy of this message
There's been a few pieces of code already to show how to convert normal PHP errors in to exceptions, but if you want a simple single line you can put somewhere, try this: <?php set_error_handler(create_function('$x, $y', 'throw new Exception($y, $x);')); ?> It doesn't get any easier than that. The only catch is this must be executed in the global scope. That means you can't embed this in a class for example. Just add it near the beginning of your entire script (where you include() files for example) and that should be it! Just make sure to catch the exceptions thrown, or set a default exception handler. ---- Server IP: 69.147.83.197 Probable Submitter: 99.239.192.245 ---- Manual Page -- http://www.php.net/manual/en/language.exceptions.php Edit -- https://master.php.net/note/edit/82197 Del: integrated -- https://master.php.net/note/delete/82197/integrated Del: useless -- https://master.php.net/note/delete/82197/useless Del: bad code -- https://master.php.net/note/delete/82197/bad+code Del: spam -- https://master.php.net/note/delete/82197/spam Del: non-english -- https://master.php.net/note/delete/82197/non-english Del: in docs -- https://master.php.net/note/delete/82197/in+docs Del: other reasons-- https://master.php.net/note/delete/82197 Reject -- https://master.php.net/note/reject/82197 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#137795) next »