How to catch runtime error?

L

laszlo

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
 
T

Tad McClellan

laszlo said:
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__}.
 
A

Anno Siegel

Tad McClellan said:
That is not an error message.

That is a warning message.




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




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
 
L

laszlo

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top