Re: [PHP] Try{} Catch()



On Sun, December 23, 2007 3:50 pm, Martin Alterisio wrote:
It's not supposed to be practical, it's just a way to handle errors.
You
shouldn't rely on try/catch for algorithm implementation.

You create exceptions for errors and unexpected behavior. Then in some
other
part of the system you use try/catch to prevent the code from
terminating
abruptly. You catch the exception (you should know which exceptions
can be
thrown), and act accordingly. Either closing resources, add a log
message
with debug information, and/or sending an error message to the user.

Except that once you start trying to integrate several large bodies of
code, you have NO IDEA what exceptions can be thrown, and even less
idea where they didn't get caught and handled properly.

Worse, many times the library[ies] you are integrating to an abysmal
job of doing anyting intelligent with the catch block, and you're
stuck with something even worse than set_error_handler.

try/catch works great for small/medium projects, or even large
well-documented projects perhaps, but as soon as you start trying to
integrate several projects...

Well, in MY experience, try/catch just ended up biting me in the butt...

ymmv
naiaa
ianal

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?
.



Relevant Pages

  • Re: OOP php user system
    ... and TRY/CATCH maybe. ... bool res = f.SetI; ... especially if the exceptions can only be identified by text strings. ... me the 'i' in iTeachersPerStudent isn't the amateurist's mistake of using ...
    (comp.lang.php)
  • Re: How expsensive in terms of performance is try / catch
    ... Both of your examples have the same number of try/catch blocks. ... if each try/catch block reduced performance, ... try/catch blocks that simply eat exceptions are bad. ... your own code, but you can't avoid dealing with them altogether, and ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [PHP] Try{} Catch()
    ... shouldn't rely on try/catch for algorithm implementation. ... You create exceptions for errors and unexpected behavior. ... Either closing resources, add a log message ... and/or sending an error message to the user. ...
    (php.general)
  • Re: Exception handling?
    ... try/catch is bad, which it usually is. ... clauses you have and the effectiveness with which you're using exceptions. ... I once wrote code for an OS that threw an exception when an API failed. ... Part of the problem is that not everything is encapsulable in RAII. ...
    (microsoft.public.vc.mfc)
  • Re: new without delete: what will happen
    ... If you're writing try/catch a lot, you're probably not using exceptions ... The idea is to have destructors of local objects perform ...
    (microsoft.public.vc.mfc)