Stopping/exiting the parent method...

Questions, tips and tricks and techniques for scripting in Servoy

Stopping/exiting the parent method...

Postby john.allen » Mon Jun 29, 2009 12:32 am

Sorry this is really elementary but I don't think I've ever done it and for the world of me I can't seem to figure it out. I have a whole series of transactions that are started by a single method. If some event occurs in one of the child methods and, based on that, I want to stop the parent method as well from executing how do I do that? Stopping and exiting the child method is simply 'return' but what do I do to stop the parent/calling method? I think it has to be something simple but I can't seem to see it. (3.5 is where I'm trying to do this).
John Allen
Stanford University
john.allen
 
Posts: 515
Joined: Wed Jul 02, 2003 10:07 pm
Location: Stanford CA USA

Re: Stopping/exiting the parent method...

Postby pbakker » Mon Jun 29, 2009 9:06 am

You could throw an exception:
Code: Select all
throw('myOwnCustomExceptionCodeHere')

That would terminate all running methods.
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: Stopping/exiting the parent method...

Postby Thomas Parry » Mon Jun 29, 2009 2:03 pm

Can we not wrap the methods called by the parent in a try-catch block and capture the exception when thrown?
Tom Parry
Prospect IT
Java/C++/Servoy/Jasper Reports/Simulation/Service Applications
http://www.prospect-saas.biz
Thomas Parry
 
Posts: 498
Joined: Thu Jan 10, 2008 8:48 pm
Location: Ottawa, Canada

Re: Stopping/exiting the parent method...

Postby pbakker » Mon Jun 29, 2009 2:08 pm

sure you can
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: Stopping/exiting the parent method...

Postby john.allen » Mon Jun 29, 2009 8:06 pm

OK. Now I don't feel so bad. I was thinking there was some sort of 'exit' function that got you out of the parent script as well and I just couldn't remember it... I think it would be kind of good thing to just be able to just stop the entire method from the child method on some event without having to wrap the child method in an error trap. Haven't really thought it through but I always like simpler!

Thanks for getting me back on track.
John Allen
Stanford University
john.allen
 
Posts: 515
Joined: Wed Jul 02, 2003 10:07 pm
Location: Stanford CA USA

Re: Stopping/exiting the parent method...

Postby kazar » Mon Jun 29, 2009 10:56 pm

Even when using development tools that have a function or command that will halt the whole stack I never use that command (such as FMP's Halt Script) anyhow. Instead, the sub-methods being called pass a result back to the master, and the logic controlling whether and how to continue overall processing is contained in the master.

I find this approach preferable for two reasons:

1 -- the sub-methods remain more modular. They can be reused someday as "slaves of a different master" which you may not want to terminate under the same conditions.

2 -- code-review is easier ... a read-through of the master script will reveal how the routine tests for conditions/state, rather than having to trace through to sub-routines in order to get the picture.

kazar
User avatar
kazar
 
Posts: 367
Joined: Sat Sep 13, 2003 9:59 pm
Location: New York City

Re: Stopping/exiting the parent method...

Postby john.allen » Mon Jun 29, 2009 11:08 pm

Hi Ilyse!

Long time since I've seen you. Of course you are correct. In general that's definitely the way to go. This was something that was rather short right at the beginning of a long method that also has numerous sub-methods. If there was a certain result I'm giving a message to the user to change something and then stopping the method. Really it should (and will) just be in the parent method itself. But I was just thinking of saving space within the method (I don't like scrolling - what can I say!) and moving it to a child method. But maybe you are right and I was thinking back to my FM days and that was where I got the notion of a 'Halt Script' or something!
John Allen
Stanford University
john.allen
 
Posts: 515
Joined: Wed Jul 02, 2003 10:07 pm
Location: Stanford CA USA

Re: Stopping/exiting the parent method...

Postby kazar » Mon Jun 29, 2009 11:31 pm

john.allen wrote:(I don't like scrolling - what can I say!)


LOL. Two words:

code. folding.

:-D
User avatar
kazar
 
Posts: 367
Joined: Sat Sep 13, 2003 9:59 pm
Location: New York City


Return to Methods

Who is online

Users browsing this forum: No registered users and 36 guests