Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 18th, 2005, 9:06 AM   #1
bobfox
Newbie
 
Join Date: Aug 2005
Posts: 17
Rep Power: 0 bobfox is on a distinguished road
Perl Error Handling

Hello everyone...

I'm writing a program in Perl. I am trying to handle errors using the warn function.

Problem is... I want it to do more than one thing in the event of an error... During a warn I need it to execute a block of code.

Everything I try { } and ( ) doesn't seem to work.

$sock or warn ("print something");

Needs to be something like:

$sock or {
warn ("print something");
logfunction (logError);
}

I keep getting errors doing it this way.

Any suggestions?

Thanks.
bobfox is offline   Reply With Quote
Old Aug 18th, 2005, 10:14 AM   #2
skuinders
Hobbyist Programmer
 
skuinders's Avatar
 
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4 skuinders is on a distinguished road
if block?

assuming $sock is boolean
if (!$sock) {
  warn ("print something");
  logfunction (logError);
}
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand."
- B. Russell

http://web.bryant.edu/~srk2
skuinders is offline   Reply With Quote
Old Aug 18th, 2005, 10:48 AM   #3
sykkn
Hobbyist Programmer
 
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5 sykkn is on a distinguished road
if you are trying to use the warn in the case of a function call failure ... then something like this might work for you

function() || warn('error message') && warnFunction();

as illustrated here:

#!/usr/bin/perl -w

use strict;

sub doSomething() {
        return(0);
}

sub warnFunction() {
        print "Warn Function\n";
}

doSomething() || warn('called warn()',"\n") && warnFunction();

otherwise ... if you are just trying to test the value of a variable ... then use an 'if' as stated above.
__________________
[ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ];
/* Don't make me use it! */
sykkn is offline   Reply With Quote
Old Aug 18th, 2005, 4:12 PM   #4
bobfox
Newbie
 
Join Date: Aug 2005
Posts: 17
Rep Power: 0 bobfox is on a distinguished road
Thanks for your help. I had if !($sock) instead of if (!$sock)
bobfox is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:34 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC