I agree with Abigail that it definitely matters who's going to see this message. If it's going to show up in an error log, I just make sure it's a unique string that I can grep for easily, something like this:
foo or die "sorrow, pestilence, Notepad: $!$/";As long as I don't use the same error string twice, it takes about two seconds to find the place where the problem is.
If it's an error message that an end user is going to see, I do something rather different...
open FOO, "<$foo" or fatalerror "Couldn't Read Foo: $!"; # and off in an include file somewhere I define... sub fatalerror { my $email = $ENV{SERVER_ADMIN}; use HTML::Entities; my $code = encode_entities(shift); my $fm = <<"FRIENDLYMESSAGE"; <p class=\"error\">Oops! I seem to have run into a problem! This is probably a bug in the software on this site, something that the webmaster needs to fix. If this problem persists, you can contact the webmaster at <a href="mailto:$email">$email</a> and report the problem. It might get fixed faster if you include the exact technical error code that follows. </p> <p class=\"error\">Technical Error Code: $code</p> FRIENDLYMESSAGE # And then I output a page containing $fm in the # usual fashion. }
This is for CGI, which in my case is the only kind of interface used for stuff that end users see, but you can imagine a similar sort of thing for GUI stuff.
In reply to Re: Perl Style: About error messges opening files
by jonadab
in thread Perl Style: About error messges opening files
by demerphq
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |