You can use die and eval (it works like "try" and "catch" in java or C#)

   sub db_routine {
        $err = do_db_operation;
        if ($err) {
            die $err;
        }
        else {
            do_anything_else;
            return $results;
        }
}

    eval {$res = db_routine;}; print "Got an error $@" if $@ 

Andray Siletsky
Sr. Software Engineer
Intel Co.
 
SC2-12
2200 Mission College blvd.
Santa Clara, CA 95052-8119
 
t:(408) 765-8459

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: Tuesday, July 26, 2005 12:05 PM
To: [email protected]
Subject: ActivePerl Digest, Vol 18, Issue 17

Send ActivePerl mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://listserv.ActiveState.com/mailman/listinfo/activeperl
or, via email, send a message with subject or body 'help' to
        [EMAIL PROTECTED]

You can reach the person managing the list at
        [EMAIL PROTECTED]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of ActivePerl digest..."


Today's Topics:

   1. Exit from Sub Routine without exit the script
      (Chandrasekaran Suresh)
   2. RE: Exit from Sub Routine without exit the script (Bowie Bailey)
   3. Re: Exit from Sub Routine without exit the script ($Bill Luebkert)
   4. RE: Exit from Sub Routine without exit the script (Brian Raven)
   5. Re: Exit from Sub Routine without exit the script (Brent G)


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

Message: 1
Date: Tue, 26 Jul 2005 04:56:17 -0700 (PDT)
From: Chandrasekaran Suresh <[EMAIL PROTECTED]>
Subject: Exit from Sub Routine without exit the script
To: [email protected]
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=iso-8859-1

Hello, 

 I am calling a perl module from my one perl script.
Inside the module I am working with some database. IF
found error during the execution in the module in need
to exit from the subroutine and continues the
process.. 

How to handle this situation

Please advice  me

Regards,
Suresh C

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


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

Message: 2
Date: Tue, 26 Jul 2005 09:19:53 -0400
From: Bowie Bailey <[EMAIL PROTECTED]>
Subject: RE: Exit from Sub Routine without exit the script
To: [email protected]
Message-ID:
        <[EMAIL PROTECTED]>
Content-Type: text/plain;       charset="iso-8859-1"

From: Chandrasekaran Suresh [mailto:[EMAIL PROTECTED]
> 
>  I am calling a perl module from my one perl script.
> Inside the module I am working with some database. IF
> found error during the execution in the module in need
> to exit from the subroutine and continues the
> process.. 

You can always use the "return" command to exit from a subroutine (in a
module or not).  Then you can check the return code of the routine, if
you
provided one, to determine if it exited normally or not.

For example:

    sub db_routine {
        $err = do_db_operation;
        if ($err) {
            return $err;
        }
        else {
            do_anything_else;
            return $results;
        }

    $res = db_routine;
    if ($res =~ /error/i) {
        print "Got an error\n";
    }

Of course, you can make this as complex as needed.  My database routines
are
a bit more complex to allow for better error reporting and more
information
returned from the routine.

Bowie


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

Message: 3
Date: Tue, 26 Jul 2005 06:26:30 -0700
From: "$Bill Luebkert" <[EMAIL PROTECTED]>
Subject: Re: Exit from Sub Routine without exit the script
To: Chandrasekaran Suresh <[EMAIL PROTECTED]>
Cc: [email protected]
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=us-ascii

Chandrasekaran Suresh wrote:

> Hello, 
> 
>  I am calling a perl module from my one perl script.
> Inside the module I am working with some database. IF
> found error during the execution in the module in need
> to exit from the subroutine and continues the
> process.. 
> 
> How to handle this situation

sub my_sub {

...

if ($error_occurred) {
        return 0;       # 0 or undef returned on failure
                        # you could also store a string
                        # in a global and add a method
                        # to retrieve the error string.
# you could also return the string as part of your return
# by returning an array:
        return (0, "Fubar error occurred");
# or you could number each possible error and return if
(probably as a negative number):
        return -12;     # where error (-)12 is "Fubar error occurred"

}

...

return 1;       # 1 or true returned on good execution

}


-- 
  ,-/-  __      _  _         $Bill Luebkert
Mailto:[EMAIL PROTECTED]
 (_/   /  )    // //       DBE Collectibles    Mailto:[EMAIL PROTECTED]
  / ) /--<  o // //      Castle of Medieval Myth & Magic
http://www.todbe.com/
-/-' /___/_<_</_</_    http://dbecoll.tripod.com/ (My Perl/Lakers stuff)


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

Message: 4
Date: Tue, 26 Jul 2005 14:39:08 +0100
From: "Brian Raven" <[EMAIL PROTECTED]>
Subject: RE: Exit from Sub Routine without exit the script
To: <[email protected]>
Message-ID:
        <[EMAIL PROTECTED]>
Content-Type: text/plain; charset="us-ascii"

[EMAIL PROTECTED] wrote:
> Hello,
> 
>  I am calling a perl module from my one perl script.
> Inside the module I am working with some database. IF found
> error during the execution in the module in need to exit from
> the subroutine and continues the process..
> 
> How to handle this situation
> 
> Please advice  me

It's a bit difficult to give advice without a more precise idea of what
it is you are trying to do. Perhaps you could provide a short example
script that illustrates your problem.

HTH

-- 
Brian Raven
 


-----------------------------------------------------------------------
The information contained in this e-mail is confidential and solely 
for the intended addressee(s). Unauthorised reproduction, disclosure, 
modification, and/or distribution of this email may be unlawful. If you 
have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message 
do not necessarily reflect those of LIFFE Holdings Plc or any of its
subsidiary companies.
-----------------------------------------------------------------------




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

Message: 5
Date: Tue, 26 Jul 2005 08:52:14 -0500
From: Brent G <[EMAIL PROTECTED]>
Subject: Re: Exit from Sub Routine without exit the script
To: Chandrasekaran Suresh <[EMAIL PROTECTED]>
Cc: [email protected]
Message-ID: <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Chandrasekaran Suresh wrote:
> Hello, 
> 
>  I am calling a perl module from my one perl script.
> Inside the module I am working with some database. IF
> found error during the execution in the module in need
> to exit from the subroutine and continues the
> process.. 
> 
> How to handle this situation
> 
> Please advice  me
> 
> Regards,
> Suresh C
> 

http://www.catb.org/~esr/faqs/smart-questions.html


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

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

End of ActivePerl Digest, Vol 18, Issue 17
******************************************

_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to