Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exit sub routine

Status
Not open for further replies.

robdunfey

Technical User
Apr 26, 2002
110
GB
Hi,

I have a few perl scripts, that are dependent on each other. When I run one script and it encounters an error I want it to call a sub routine that prints an error message then exits the script. But it must also tell the script that is running the program that it has failed, so that program can enter a sub to deal with the error and also exit. My problem is killing a script from a sub routine and also telling the program that called the script its has failed. Can anyone point me in the direction of a nice simple example?

Many Thanks,

Rob
 
You might try this.....

if ($this == $that) {
...Do something...
}
else {
$yourErrorCode = "Bad Things.... $!";
&ExitError($yourErrorCode);
}

sub ExitError {
$tmpErr = @_;
... do something with error ...
exit(1); .... or
exit ($tmpErr);
}

Depending on how you have things put together... You may have to include this sub with each script called, unless you package it and make it OO style (Which I would suggest).


...... You could also do it right in the code.....

if ($this == $that) {
... do the right thing ...
}
else {
$yourErrorCode = "Bad Things ... $!";
exit($yourErrorCode);
}

Check out the perl man on exit(). You should have no trouble sending a message back to the calling script or program for that matter.... as long as it is listening for it.


------------------------------

The beatings will stop when morale improves!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top