runtime errors - Q how to do this 
Author Message
 runtime errors - Q how to do this

Q How can I trap runtime errors in PERL without using
eval()  ??
I want to be able to pick up the $! errormessage,
but using something like the usual BASIC method as follows:

ON ERROR gosub  errorhandler
..
..
SUB errorhandler
$error = $!
print <outputfile> "runtime error: ", $error
RETURN

So, what is the equivalent in PERL???

any help would be appreciated.
cheers,
{*filter*}

--
{*filter*} Nickalls

Department of Anaesthesia, City Hospital, Nottingham, UK.



Wed, 18 Jun 1902 08:00:00 GMT  
 runtime errors - Q how to do this

Quote:
>> On 29 May 2000 17:52:01 GMT,

> Q How can I trap runtime errors in PERL without using
> eval() ??  I want to be able to pick up the $!
> errormessage, but using something like the usual BASIC
> method as follows:

You use eval.

If you want to write it in BASIC, write it in BASIC.
If you want to write it in perl, write it in perl.

Use the appropriate paradigms for the language at hand.
"perldoc -f eval" has quite a lot of info.

Why would you want to avoid eval anyway?

hth
t
--
"Trying is the first step towards failure"
                                           Homer Simpson



Wed, 18 Jun 1902 08:00:00 GMT  
 runtime errors - Q how to do this


Quote:
> Q How can I trap runtime errors in PERL without using
> eval()  ??

You trap them:

        perldoc -q trap

        Found in /usr/lib/perl5/5.00503/pod/perlfaq8.pod
          How do I trap control characters/signals?

Also, checkout the special %SIG hash, and it's special __WARN__ and
__DIE__ keys in perlvar.

--Ala



Wed, 18 Jun 1902 08:00:00 GMT  
 runtime errors - Q how to do this
Thanks Tony,
but as far as I can see using eval() I will have to
use it for every calculation where I might accidentally be
dividing by zero..fine in a small prog, but not here.

I am reading in line-by-line an input file with parameters,
so if one of the parameters is accidentally not a valid number
etc, then I will likely get a runtime error.
I want to do  IF error --> next line etc
and just pick up the errormessage and print it to the screen.
Surely there must be a way without having to resourt to eval??

I have already written the program in BASIC, and in the
process of translating it to PERL.

cheers,
{*filter*}

--
{*filter*} Nickalls

Department of Anaesthesia, City Hospital, Nottingham, UK.



Wed, 18 Jun 1902 08:00:00 GMT  
 runtime errors - Q how to do this
Thanks Ala, I will checkout your reference on trapping.

cheers,
{*filter*}

--
{*filter*} Nickalls

Department of Anaesthesia, City Hospital, Nottingham, UK.



Wed, 18 Jun 1902 08:00:00 GMT  
 runtime errors - Q how to do this

Quote:
> Q How can I trap runtime errors in PERL without using
> eval()  ??
> I want to be able to pick up the $! errormessage,
> but using something like the usual BASIC method as follows:

> ON ERROR gosub  errorhandler
> ..
> ..
> SUB errorhandler
> $error = $!
> print <outputfile> "runtime error: ", $error
> RETURN

> So, what is the equivalent in PERL???

There isnt an equivalent in Perl - one uses eval.  You can infact do
something like :

sub handler
{

Quote:
}

$SIG{__WARN__} = \&handler;

open (FOO,'/etc/shadow') || warn $!;

print "This continues\n";

Though I dont see many people using this kind of thing in favour of the
eval().

/J\
--
Yeah, you know, boys, a nuclear reactor is a lot like a woman. You just
have to read the manual and press the right buttons.
--
fortune oscar homer



Wed, 18 Jun 1902 08:00:00 GMT  
 runtime errors - Q how to do this
Jonathan,

With this sort of construction one still has to
put || warn $!  on the end of every command you think might
generate an error - in which case you might just as
well use Eval().

We need some method of making perl direct any runtime
problem into some global recoverable errortrap
we can have access to, and hence continue/return etc.

Am I missing something here, or am I just trying to do
the ompossible??  :-)

cheers,
{*filter*}

--
{*filter*} Nickalls

Department of Anaesthesia, City Hospital, Nottingham, UK.



Wed, 18 Jun 1902 08:00:00 GMT  
 runtime errors - Q how to do this

 | Am I missing something here, or am I just trying to do
 | the ompossible??  :-)

you must meditate on the question, grasshopper, before you receive
enlightenment..

do I warn or die?
perl finds parroty error
it's bleedin' demised

:D

hey, is this good enough for the haiku contest?

the format IS 5-7-5 right? I forget :|

--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.  



Wed, 18 Jun 1902 08:00:00 GMT  
 runtime errors - Q how to do this

Quote:

>do I warn or die?
>perl finds parroty error
>it's bleedin' demised

>:D

>hey, is this good enough for the haiku contest?

Sorry, no seasonal reference, next please ;-)

big

(who _still_ chuckles about "hippopotamus, anti-hippopotamus, annihilation")



Wed, 18 Jun 1902 08:00:00 GMT  
 runtime errors - Q how to do this



 |
 |  | Am I missing something here, or am I just trying to do
 |  | the ompossible??  :-)
 |
 | you must meditate on the question, grasshopper, before you receive
 | enlightenment..
 |
 | do I warn or die?
 | perl finds parroty error
 | it's bleedin' demised

on 2nd thought, I wonder if it would be funnier if there *was* a 'parity
error' in there suchlike: "perl finds a parroty error" (8 instead of 7)
*chuckle* ....ANYway........

 | :D
 |
 | hey, is this good enough for the haiku contest?
 |
 | the format IS 5-7-5 right? I forget :|

--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.  



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. HELP WANTED: runtime error message: VARIABLE ERROR.

2. Win32::AdminMisc and "error: Runtime Error"

3. Help w/newbie Perl runtime Error

4. EventLog Gets Runtime Exception Error

5. ExtUtils::MakeMaker runtime error

6. Runtime Error in LanMan EnumShares

7. HELP! Runtime Exception Error

8. Error : Runtime exception with Win32::ODBC

9. Runtime Error in Perl

10. Error : Runtime exception with win32Api...

11. Help w/newbie Perl runtime Error

12. Piddly runtime error using DB_File and Fcntl

 

 
Powered by phpBB® Forum Software