Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Error Handling Misconception

by bobn (Chaplain)
on Sep 03, 2003 at 22:16 UTC ( #288750=note: print w/replies, xml ) Need Help??


in reply to Error Handling Misconception

if the eval fails, it your function probably also returned a false value, which caused your while loop to skip the if ( $@ ) code.

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

All code given here is UNTESTED unless otherwise stated.

Replies are listed 'Best First'.
Re: Re: Error Handling Misconception
by Anonymous Monk on Sep 03, 2003 at 22:26 UTC

    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.

      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.

      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

      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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2020-06-06 09:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (41 votes). Check out past polls.

    Notices?