How to catch runtime error?

Discussion in 'Perl Misc' started by laszlo, Oct 23, 2003.

  1. laszlo

    laszlo Guest

    Consider the following program

    $repeat=1000;

    for ($i=0; $i<$repeat;$i++) {println();}
    if ($@) {print "$@"; die;}
    print "done";

    sub println {
    my $s = shift;
    #if (! defined($s)) {$s = "";}
    print "$s\n";
    if ($@) {print "$@"; die;}
    }

    If I run it from command mode with -W parameter I get

    "Use of unitialized value in concatenation (.) or string in a.txt line
    9.

    error message for every execution of the sub

    However if I use in IIS (WIN2000 Service pack 4; Active State Perl
    5.8 806) inside a larger program as part of an

    eval({$program})
    if ($@) {report the error; die}

    statement, the program does not report any error just dies and the
    browser (IE 6.0) shows an irrelevant "the page cannot be displayed"
    error message.

    If I lower thwe value of $repeat to 100 or less, the program finishes
    w/o any error message , also if I remove the # comment before the

    #if (! defined($s)) {$s = "";}

    line, the program runs w/o any problem for reasonable sizes.

    In my website environment the program runs, but no error message is
    given

    http://lzkiss.netfirms.com/cgi-bin/igperl/igp.pl?dir=test&name=test

    Any help appreciated

    laszlo
     
    laszlo, Oct 23, 2003
    #1
    1. Advertising

  2. laszlo <> wrote:

    > If I run it from command mode with -W parameter I get
    >
    > "Use of unitialized value in concatenation (.) or string in a.txt line
    > 9.
    >
    > error message for every execution of the sub



    That is not an error message.

    That is a warning message.


    > However if I use in IIS (WIN2000 Service pack 4; Active State Perl
    > 5.8 806) inside a larger program as part of an
    >
    > eval({$program})
    > if ($@) {report the error; die}
    >
    > statement, the program does not report any error just dies and the
    > browser (IE 6.0) shows an irrelevant "the page cannot be displayed"
    > error message.



    Does it put the message in the web server's log?


    > Any help appreciated



    Warnings are not trapped the same way as errors, see

    perldoc -f eval

    for how to use $SIG{__WARN__}.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Oct 23, 2003
    #2
    1. Advertising

  3. laszlo

    Anno Siegel Guest

    Tad McClellan <> wrote in comp.lang.perl.misc:
    > laszlo <> wrote:
    >
    > > If I run it from command mode with -W parameter I get
    > >
    > > "Use of unitialized value in concatenation (.) or string in a.txt line
    > > 9.
    > >
    > > error message for every execution of the sub

    >
    >
    > That is not an error message.
    >
    > That is a warning message.
    >
    >
    > > However if I use in IIS (WIN2000 Service pack 4; Active State Perl
    > > 5.8 806) inside a larger program as part of an
    > >
    > > eval({$program})
    > > if ($@) {report the error; die}
    > >
    > > statement, the program does not report any error just dies and the
    > > browser (IE 6.0) shows an irrelevant "the page cannot be displayed"
    > > error message.

    >
    >
    > Does it put the message in the web server's log?
    >
    >
    > > Any help appreciated

    >
    >
    > Warnings are not trapped the same way as errors, see
    >
    > perldoc -f eval
    >
    > for how to use $SIG{__WARN__}.


    As an alternative, one can make the warning in question fatal and
    catch it in eval. In this case:

    eval { use warnings FATAL => qw( uninitialized); <whatever> }

    That is sometimes easier than fiddling with a handler.

    Anno
     
    Anno Siegel, Oct 24, 2003
    #3
  4. laszlo

    laszlo Guest

    > >
    > > perldoc -f eval
    > >
    > > for how to use $SIG{__WARN__}.

    >
    > As an alternative, one can make the warning in question fatal and
    > catch it in eval. In this case:
    >
    > eval { use warnings FATAL => qw( uninitialized); <whatever> }
    >
    > That is sometimes easier than fiddling with a handler.
    >
    > Anno


    Thanks for both info. I put

    use warnings FATAL => qw(all);

    statement in front of my text to be avaluated, and the interpreter
    faithfully listed all the warnings.
     
    laszlo, Oct 27, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Black
    Replies:
    8
    Views:
    4,160
    Xenos
    Aug 20, 2004
  2. chris
    Replies:
    4
    Views:
    756
    yuvalif
    Nov 15, 2005
  3. Adam
    Replies:
    9
    Views:
    576
    red floyd
    Feb 2, 2006
  4. Marteno Rodia

    catch doesn't catch a thrown exception

    Marteno Rodia, Aug 3, 2009, in forum: Java
    Replies:
    5
    Views:
    569
    Daniel Pitts
    Aug 5, 2009
  5. Reza Roby
    Replies:
    5
    Views:
    112
    Reza Roby
    Jan 22, 2004
Loading...

Share This Page