Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:1442 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55728 invoked from network); 11 May 2003 15:26:47 -0000 Received: from unknown (HELO anchor-post-35.mail.demon.net) (194.217.242.85) by pb1.pair.com with SMTP; 11 May 2003 15:26:47 -0000 Received: from grendels.demon.co.uk ([194.222.209.35] helo=earth.libertas) by anchor-post-35.mail.demon.net with esmtp (Exim 3.36 #2) id 19Esiq-0003X9-0Z for internals@lists.php.net; Sun, 11 May 2003 16:26:46 +0100 Received: from grendels by earth.libertas with local (Exim 3.36 #1 (Debian)) id 19EswW-0000e2-00 for ; Sun, 11 May 2003 16:40:52 +0100 To: internals@lists.php.net Date: Sun, 11 May 2003 16:40:51 +0100 User-Agent: KMail/1.5.9 References: <5.1.0.14.2.20030504021938.09452980@mailbox.rwth-aachen.de> <1052077704.11371.319.camel@hasele> In-Reply-To: <1052077704.11371.319.camel@hasele> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message-ID: <200305111640.51779.postmaster@terrarium.f9.co.uk> Sender: Theo Spears Subject: Re: [PHP-DEV] exceptions instead of errors From: postmaster@terrarium.f9.co.uk (Theo Spears) On Sunday 04 May 2003 20:48, Sterling Hughes wrote: > Just a note that I'd really like to see this. One of the great things > about exceptions will be: > > try { > $m =3D mysql_connect("localhost", "user", "pass"); > $sth =3D mysql_query("select bar from foo", $m); > while ($row =3D mysql_fetch_array($sth)) { > echo $row[0]; > } > mysql_close($m); > } catch (exception $e) { > echo $e->getMessage(); > } > > This allows you to remove all the nasty if ($conn) could, and move your > error handling into a singular place. I *really* would like this for > internal functions. We could also make a new type of exception > "internalexception," which a user has to specifically catch. This way > unless you explictly specify that you want to catch an > internalexception, it will default to just outputting an error message. > Although this approach would certainly simplify handling errors it seems to= me=20 it would give everyone big problems when it comes to predicting the control= =20 flow of their programs. For example function db_connect ( $db_name ) { $link =3D mysql_connect(); if ( ! mysql_select_db( $db_name, $link ) ) { mysql_select_db ( BACKUP_DB_NAME, $link ); } } now, depending on whether you do try { db_connect ( 'foo' ); } catch (exception e) { } or just=20 db_connect ( 'foo' ); The function will behave differently. Even if all new PHP5 code uses=20 exceptions there is a lot of code which doesn't, and so the principles of=20 information hiding say you would have to make sure any code which calls a=20 function in a separate module has to make sure that function isn't inside a= =20 try{}catch{} block, and the only functions in the same module which are=20 inside try{}catch{} blocks that catch internal exceptions don't call any=20 functions in external modules. Personally I would prefer a system similar to the @ notation which suppress= es=20 error messages, possibly make %function() or similar cause the function to= =20 raise an exception. (The engine could handle this by silently dropping all= =20 exceptions from internal functions that weren't called with the relevant=20 prefix). Just my =A30.02 Theo Spears