Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: unless/if

by Moron (Curate)
on Oct 11, 2005 at 16:05 UTC ( #499205=note: print w/replies, xml ) Need Help??

in reply to unless/if

To question assumptions as I usually do these days... die is normally for programming errors, whereas this looks more like a fatal data issue, which should be handled in a different way, e.g.:
<>; if ( /^aaa/ ) { DataFatal( "problem-description, for $_" ); } chomp; my $file = $_; if ( /okregexp/ ) { #do something } else { #matches neither! # this case wasn't mentioned, by the way! } sub DataFatal { # fatal messaging. print STDERR "*** DATA FATAL ***\n+++ " . shift . " +++\n"; exit 1; }


Free your mind

Replies are listed 'Best First'.
Re^2: unless/if
by sth (Priest) on Oct 11, 2005 at 18:41 UTC

    Unless I am missing something, printing to STDERR and then exiting is not gaining anything over die "blah\n", which is going to exit with a non-zero status. Is this to avoid a possible $SIG{DIE}?

      die produces debugging information suitable for programmers but annoying for users. Programmers want to know about line numbers. Users want information that will indicate a functional solution and don't like to see even partial stack traces - it makes them believe, quite reasonably, that the program wasn't actually ready for release and that someone didn't do their job and maybe should even be fired - in fact it's hard to argue against that.


      Free your mind

        If you stick a "\n" on the end of the string you pass to die, you won't get a line number.

        Apart from better readability and being a standard idiom, the nice thing about using die is you can catch it in a eval, making it possible to deal with exceptional conditions at a higher level.

        ...and to add to sgifford's reply, adding a "\n" to the end of the a warn statement will eliminate the lines numbers being printed, just like die.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://499205]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2018-05-26 18:07 GMT
Find Nodes?
    Voting Booth?