note 78591 added to language.exceptions

From: Date: Thu, 18 Oct 2007 11:41:30 +0000
Subject: note 78591 added to language.exceptions
Groups: php.notes 
Request: Send a blank email to php-notes+get-131492@lists.php.net to get a copy of this message
@serenity: of course you need to throw exception within the try block, catch will not watch fatal errors, nor less important errors but only exceptions that are instanceof the exception type you're giving. Of course by within the try block, i mean within every functions call happening in try block. For example, to nicely handle old mysql errors, you can do something like this: <?php try { $connection = mysql_connect(...); if ($connection === false) { throw new Exception('Cannot connect do mysql'); } /* ... do whatever you need with database, that may mail and throw exceptions too ... */ mysql_close($connection); } catch (Exception $e) { /* ... add logging stuff there if you need ... */ echo "This page cannot be displayed"; } ?> By doing so, you're aiming at the don't repeat yourself (D.R.Y) concept, by managing error handling at only one place for the whole. ---- Server IP: 195.221.21.36 Probable Submitter: 88.169.213.8 ---- Manual Page -- http://www.php.net/manual/en/language.exceptions.php Edit -- https://master.php.net/note/edit/78591 Del: integrated -- https://master.php.net/note/delete/78591/integrated Del: useless -- https://master.php.net/note/delete/78591/useless Del: bad code -- https://master.php.net/note/delete/78591/bad+code Del: spam -- https://master.php.net/note/delete/78591/spam Del: non-english -- https://master.php.net/note/delete/78591/non-english Del: in docs -- https://master.php.net/note/delete/78591/in+docs Del: other reasons-- https://master.php.net/note/delete/78591 Reject -- https://master.php.net/note/reject/78591 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131492) next »