Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: unless/if

by sth (Priest)
on Oct 11, 2005 at 18:41 UTC ( #499251=note: print w/ replies, xml ) Need Help??


in reply to Re: unless/if
in thread unless/if

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}?


Comment on Re^2: unless/if
Re^3: unless/if
by Moron (Curate) on Oct 12, 2005 at 08:17 UTC
    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.

    -M

    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.

        Adding the "\n" to get rid of traceback info is the least part of the problem and does not address the real situation that professional programmers will frequently encounter, requiring more to be done on encountering a fatal error that needs to be brought to user's rather than just an IT person's attention and which may need support some time after the fact.
        <condition> or ProjectName::Die( $gddref, "message content" ); # in package ProjectName sub Die my $gddref = shift; # ref. to global data dictionary my $content = shift; my $UICB = $gddref -> { CB }{ UIOUT }; my $logref = $gddref -> { FH }{ LOGOUT }; &$UICB( "FATAL ERROR: $content" ); # which may or may not end up # using die depending # on the user interface print $logref ( ProjFormatTime( localtime() ) . ": $content\n"; exit 1; # having met such particular messaging requirements # die with or without "\n" is no longer an obvious idea. }
        which is more to type than:<code> Die( "

        -M

        Free your mind

      ...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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://499251]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2014-12-25 04:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls