way to exit script

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

way to exit script

David Spectar
Is there a way to exit the script no matter what
nesting the code may be.

example:

foo()
{
   bar();
}

bar()
{
  exit_script;
}

foo();



               
__________________________________
Yahoo! Music Unlimited
Access over 1 million songs. Try it free.
http://music.yahoo.com/unlimited/


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: way to exit script

Shankar Unni
David Spectar wrote:
> Is there a way to exit the script no matter what
> nesting the code may be.

You can always throw a magic exception and catch it at the outermost
level.  This is especially useful if you have embedded bsh in some Java
application: you can catch the TargetError and examine the nested
exception, and treat it as a "normal direct exit"..



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: way to exit script

Philippe Faes
In reply to this post by David Spectar
Just as in plain java:

  int status=0; //or something else
  System.exit(status);

You can also exit by throwing an exception and not catching it, but that
should be reserved for exceptional circumstances, and probably even for
errors.

  throw new Error("Too bad, the script dies here.");

Philippe

On Wed, 2005-10-12 at 16:01 -0700, David Spectar wrote:

> Is there a way to exit the script no matter what
> nesting the code may be.
>
> example:
>
> foo()
> {
>    bar();
> }
>
> bar()
> {
>   exit_script;
> }
>
> foo();
>

--
ir. Philippe Faes
Ghent University - Department ELIS
Sint-Pietersnieuwstraat 41 -- B-9000 Gent
Tel:+32 9 264 95 25 - Fax:+32 9 264 35 94
    http://www.elis.UGent.be/~pfaes
ON5DEU   --   LPIC1  --  gpg-key:173720B6



-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: way to exit script

Alexey Zinger
Actually, I'd argue that if you really need to abort a script and not just
return from the entire script stack trace, throwing an exception and catching
it in compiled code that invoked the script might be a very graceful solution
in certain circumstances.

--- Philippe Faes <[hidden email]> wrote:

> Just as in plain java:
>
>   int status=0; //or something else
>   System.exit(status);
>
> You can also exit by throwing an exception and not catching it, but that
> should be reserved for exceptional circumstances, and probably even for
> errors.
>
>   throw new Error("Too bad, the script dies here.");
>
> Philippe
>
> On Wed, 2005-10-12 at 16:01 -0700, David Spectar wrote:
> > Is there a way to exit the script no matter what
> > nesting the code may be.
> >
> > example:
> >
> > foo()
> > {
> >    bar();
> > }
> >
> > bar()
> > {
> >   exit_script;
> > }
> >
> > foo();
> >
>
> --
> ir. Philippe Faes
> Ghent University - Department ELIS
> Sint-Pietersnieuwstraat 41 -- B-9000 Gent
> Tel:+32 9 264 95 25 - Fax:+32 9 264 35 94
>     http://www.elis.UGent.be/~pfaes
> ON5DEU   --   LPIC1  --  gpg-key:173720B6
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Power Architecture Resource Center: Free content, downloads, discussions,
> and more. http://solutions.newsforge.com/ibmarch.tmpl
> _______________________________________________
> Beanshell-users mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/beanshell-users
>


Alexey
2001 Honda CBR600F4i (CCS)
1992 Kawasaki EX500
http://bsheet.sourceforge.net


               
__________________________________
Yahoo! Music Unlimited
Access over 1 million songs. Try it free.
http://music.yahoo.com/unlimited/


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

Re: way to exit script

David Spectar
In reply to this post by David Spectar
I can see the merit in throwing an exception. The only
problem is that our customers might cave a
catch(Exception) or catch (Throwable) in their script,
thus defeating the purpose. Certainly not System.exit.
In fact we are dying for a way to restrict that. But
Pat told us at javaOne that this is an up an coming
feature.

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]]
On Behalf Of Alexey Zinger
Sent: Thursday, October 13, 2005 11:27 AM
To: beanshell-users
Subject: Re: [Beanshell-users] way to exit script

Actually, I'd argue that if you really need to abort a
script and not just
return from the entire script stack trace, throwing an
exception and catching
it in compiled code that invoked the script might be a
very graceful solution
in certain circumstances.


               
__________________________________
Yahoo! Music Unlimited
Access over 1 million songs. Try it free.
http://music.yahoo.com/unlimited/


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|

RE: way to exit script

Furash Gary
In reply to this post by David Spectar
System.exit(-1) if bad
System.exit(0) if cool

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]] On Behalf Of David
Spectar
Sent: Wednesday, October 12, 2005 4:02 PM
To: [hidden email]
Subject: [Beanshell-users] way to exit script


Is there a way to exit the script no matter what
nesting the code may be.

example:

foo()
{
   bar();
}

bar()
{
  exit_script;
}

foo();



               
__________________________________
Yahoo! Music Unlimited
Access over 1 million songs. Try it free.
http://music.yahoo.com/unlimited/


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads,
discussions, and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Beanshell-users mailing list [hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users


-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users