die vs exception

die vs exception

am 30.04.2007 06:27:51 von Bruce Cowin

I have written a generic sql database class which contains a method =
RunQuery which uses mssql_query. To catch errors, should I include the =
"or die" clause or should I wrap it in a try/exception block? The first =
will stop the script running but for a generic class, I was thinking it'd =
be better to raise an exception and let the calling code handle it. I'd =
be interested to hear what everyone else does.

Thanks.



Regards,

Bruce

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: die vs exception

am 30.04.2007 06:46:23 von Chris Verges

The DB and MDB2 packages in the PEAR library use a third option, which is to
return an "Error" subclass as the result rather than "throw"ing it. Prons
and cons for all, just wanted to throw in this option too.

Btw, both the DB and MDB2 packages are already generic classes that support
mssql as well as other DBMS programs, so if you're not familiar you may want
to look up the details at http://pear.php.net.

Good luck!
Chris


On 4/29/07 9:27 PM, "Bruce Cowin" wrote:

> I have written a generic sql database class which contains a method RunQuery
> which uses mssql_query. To catch errors, should I include the "or die" clause
> or should I wrap it in a try/exception block? The first will stop the script
> running but for a generic class, I was thinking it'd be better to raise an
> exception and let the calling code handle it. I'd be interested to hear what
> everyone else does.
>
> Thanks.
>
>
>
> Regards,
>
> Bruce
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: die vs exception

am 30.04.2007 23:07:35 von Bruce Cowin

Cheers, will check it out. Thanks.


Regards,

Bruce

>>> Chris Verges 30/04/2007 4:46:23 p.m. >>>
The DB and MDB2 packages in the PEAR library use a third option, which is =
to
return an "Error" subclass as the result rather than "throw"ing it. Prons
and cons for all, just wanted to throw in this option too.

Btw, both the DB and MDB2 packages are already generic classes that =
support
mssql as well as other DBMS programs, so if you're not familiar you may =
want
to look up the details at http://pear.php.net.

Good luck!
Chris


On 4/29/07 9:27 PM, "Bruce Cowin" wrote:

> I have written a generic sql database class which contains a method =
RunQuery
> which uses mssql_query. To catch errors, should I include the "or die" =
clause
> or should I wrap it in a try/exception block? The first will stop the =
script
> running but for a generic class, I was thinking it'd be better to raise =
an
> exception and let the calling code handle it. I'd be interested to hear =
what
> everyone else does.
>=20
> Thanks.
>=20
>=20
>=20
> Regards,
>=20
> Bruce
>=20
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php=20
>=20

--=20
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php=20

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php