Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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:

#! perl -slw use strict; sub divide { my( $e, $d ) = @_; return $e / $d; } my $result = eval{ divide( @ARGV ) } or die $@; print "Result: $result";

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!

#MyExceptions.pm package MyExceptions; use Exception::Class ( 'MyException', 'AnotherException' => { isa => 'MyException' }, 'YetAnotherException' => { isa => 'AnotherException', description => 'These exceptions are related to IPC' }, 'ExceptionWithFields' => { isa => 'YetAnotherException', fields => [ 'grandiosity', 'quixotic' ], alias => 'throw_fields', }, ); 1; ## Exceptions.pl #! perl -slw use strict; use MyExceptions; sub divide { my( $e, $d ) = @_; MyExceptions->throw( error => 'Divisor undefined' ) unless defined + $d; MyExceptions->throw( error => 'Divisor is zero' ) if $d == 0; return $e / $d; } # try my $result = eval { divide( @ARGV ) }; my $e; # catch if ( $e = Exception::Class->caught('MyException') ) { die 'You must supply two arguments' if $e->error eq 'Divisor undef +ined'; die 'The second argument must not be zero' if $e->error eq 'Diviso +r is zero'; die sprintf "Unanticipated exception: '%s' at \n%s\n", $e->error, +$e } else { $e = Exception::Class->caught(); ref $e ? $e->rethrow : die $e; }

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.

In reply to Re^3: eval to replace die? by BrowserUk
in thread eval to replace die? by hsmyers

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 11:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found