in reply to Re: Error Handling Misconception
in thread Error Handling Misconception

Thanks for the suggestion. That doesn't seem to be it, though: I still get the program dying w/o error if I do just this:

my $value = eval { $object->next_value() }; if ($@) { print "BLAH!\n"; } print $value, "\n";

...and no output to screen.

Replies are listed 'Best First'.
Re: Re: Re: Error Handling Misconception
by bobn (Chaplain) on Sep 03, 2003 at 23:10 UTC

    works for me:

    my $object = new wierd; my $value = eval { $object->next_value() }; if ($@) { print "BLAH!\n$@\BLAH!\n"; } print $value, "\n"; package wierd; sub new { bless {}, shift} sub next_value { die "badness"; }
    Produces:
    BLAH! badness at ./tstprog.pl line 13. BLAH!

    Are you sure you're in a situation where you can see what's printed? What happens when the routine works and $value is something printable?

    --Bob Niederman, http://bob-n.com

    All code given here is UNTESTED unless otherwise stated.

Re: Re: Re: Error Handling Misconception
by selk (Beadle) on Sep 04, 2003 at 04:18 UTC
    Make sure a header goes out to the browser before the die message. If your code dies before it had the chance to print the header, then you will likely get an error. I susally just do this at the beginning of my cgi:
    print "Content-type: text/html\n\n";
    Hope that helps,
    selk
Re: Re: Re: Error Handling Misconception
by Anonymous Monk on Sep 03, 2003 at 23:54 UTC

    I feel stupid...

    Are you sure you're in a situation where you can see what's printed? What happens when the routine works and $value is something printable?

    Once I took it out of CGI and put it in a text-file to get the minimum error, it worked. There's a bug somewhere in my CGI that I'll have to track down, but this is working fine now. Thank you muchly.