in reply to Re: eval to replace die?
in thread eval to replace die?
... consign this "post-modern", revisionist rubbish to the bit bucket and get on with life!
Perhaps you'd be more comfortable with Tcl circa 1998.
Remember, everyone else: you don't need reliable error-handling code if you never make errors.
One big drawback of string exceptions is that you have to parse strings to decide how to handle them. Parsing strings (especially to determine flow control) is fragile.
This fragility is a small risk in smaller applications, but it's worth considering alternatives in larger applications where you must handle exceptions.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: eval to replace die?
by mjscott2702 (Pilgrim) on Oct 04, 2010 at 08:44 UTC | |
| [reply] |
by chromatic (Archbishop) on Oct 04, 2010 at 14:43 UTC | |
I agree that it's difficult to use exception objects pervasively (especially when using other code), and I wouldn't have enabled this rule for Perl::Critic by default myself, but it's very much worth considering the risk and fragility of string comparisons for exception handling. | [reply] |
by BrowserUk (Patriarch) on Oct 04, 2010 at 15:48 UTC | |
the risk and fragility of string comparisons for exception handling. Even in Java, it's still "string compare". It's done at compile-time rather than run-time, which is good. But it is still string compare. But Exception::Class does not give you that advantage. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
by chromatic (Archbishop) on Oct 04, 2010 at 16:45 UTC | |
by BrowserUk (Patriarch) on Oct 04, 2010 at 17:57 UTC | |
| |
by mjscott2702 (Pilgrim) on Oct 05, 2010 at 08:33 UTC | |
In the case of a simple script that is trying to parse a file that it can't access (permissions, missing file etc), there is nothing to recover from - give the user some clue as to what went wrong, and terminate. Obviously, there are situations where the script/application/program shouldn't exit - trap the error, display the error message, log it and continue. The use of eval, catching exceptions, trapping signals etc is the choice of the programmer - TMTOWTDI. And yes, that might mean some fuzzy string comparisons.... :) | [reply] |
|
Re^3: eval to replace die?
by BrowserUk (Patriarch) on Oct 04, 2010 at 13:35 UTC | |
Perhaps you'd be more comfortable with Tcl circa 1998. No. I'm quite happy with Perl thank you. You're the one who seems to want to turn Perl into Java. One big drawback of string exceptions is that you have to parse strings to decide how to handle them. Parsing strings (especially to determine flow control) is fragile. This is typical of your response to relatively simple problems. Throw yet another layer (or three) of complicated code on top, in an attempt to make the problems "go away". Yes, error messages change occasionally. Not often, but the recent addition to "Uninitialised value" is a ready exceptional hook upon which to hang your demagoguery. Despite that no one in their right mind is going to use exception handling to deal with an uninitialised variable(*). C'st la vie. (*) Perhaps you'd offer us a worked example of how using Exception::Class to trap an uninitialised variable would have 'saved the day', when the variable name was added to the message? We could then examine the basis of your justifictions; assess the impacts, pro's & con's of your suggested alternative; explore alternative alternatives. Of course, you won't. Because you're a busy man with no time to explain your "wisdom", much less open it up to the challenge of open debate. If you're performing an exact match, a substring match, or a regular expression, any change to the text of that message in a subsequent release of Perl 5 could change the way your code behaves. So, the crux of this is that instead of the simplicity and clarity (both code and error reporting) of:
you're advising people to use (something like*): (*)This doesn't actually work. Because I can't work out how to use the module. Because there are no simple, complete, working examples that I can find. Probably because it is so insanely complicated to use that simple, complete, working examples aren't possible!
If you are unable--or more likely, unwilling--to see all the ways that can go wrong. That this is even more dependant upon string comparisons. And all the addition problems you've created for the maintenance programmers to have to unwind, sift through and reverse engineer through all those extra layers, when it does go wrong. Then I guess they'll just end up reaping what you sow. Even if you avoid comparing $e->error() to decide how to deal with the exceptions, you are still relying upon MyException->caught( 'MyException' ), which replies upon Exception::Class::Base->isa( 'MyException' ). And what does isa() do that isn't subject to exactly the same error vectors a string compare? There are times when exceptions are useful. But reaching for the insane complexity of modules like Exception::Class just in order to achieve "Java-esque"-ness; rather than something perlish-ly simple like Try::Tiny:
is madness. Java-envy of the worst kind. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] [select] |
by chromatic (Archbishop) on Oct 04, 2010 at 14:51 UTC | |
And what does isa() do that isn't subject to exactly the same error vectors a string compare? It doesn't perform a regular expression match, for one. If you've never changed the text of an exception message and then had to change the regex of handlers, good. I have. The problem with Java isn't structured exceptions. It's one part "Wow, look at how awesome we can make a fragile hierarchy!" and two parts mandatory structured exceptions. | [reply] |
by BrowserUk (Patriarch) on Oct 04, 2010 at 15:44 UTC | |
It doesn't perform a regular expression match, for one. So now you are demonising regular expressions? Should we scrap regexes all together? If you've never changed the text of an exception message and then had to change the regex of handlers, good. I have. And you've never had to restructure your exceptions? I have. I say again, how is that different? Look at all the places in the Exception Class example I posted where the (same) name of the exception (class) is embedded inside a string. Maybe those can be avoided by using Exception::Class better? If so, please enlighten us with an example. Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |
by chromatic (Archbishop) on Oct 04, 2010 at 16:43 UTC | |
by BrowserUk (Patriarch) on Oct 04, 2010 at 18:06 UTC | |