Login  Register

Antwort: Re: Return On Error

Posted by Joachim Wesner on Nov 08, 2009; 11:13pm
URL: http://imagej.273.s1.nabble.com/Return-On-Error-tp3690523p3690525.html

Hmm,

IMHO this seems not very Java-like as it also would require to augment all
calls to lower
level routines with error checking, just what one would like to avoid (Or
did I get something wrong?)

Wouldn´t it be better to use to use a user-defined exception to throw at
the intended point
of premature return and use try-catch in the run method (which
unfortunatelly also would not leave the
remaining source code totally unchanged, as one would need to declare all
intermediate routines
as "throws xxx", which however would only be required at the top of each
method, not on each call..

Just my ideas...

I hhink some time ago we already had this topic somewhere in this forum!?

Joachim




                                                                           
             Michael Doube                                                
             <m.doube@IMPERIAL                                            
             .AC.UK>                                                    An
             Gesendet von:              [hidden email]                
             ImageJ Interest                                         Kopie
             Group                                                        
             <[hidden email].                                       Thema
             GOV>                       Re: Return On Error                
                                                                           
                                                                           
             06.11.2009 21:11                                              
                                                                           
                                                                           
              Bitte antworten                                              
                    an                                                    
              ImageJ Interest                                              
                   Group                                                  
             <[hidden email].                                            
                   GOV>                                                    
                                                                           
                                                                           




Hi David

In a PlugIn the run() method returns void so you can just

return;

If one of the other methods that run() calls finds an error it could
return an error value to run(), which run() then uses to decide whether
or not to return, or do something else.

A common use is to call a showDialog() method in the run() method, which
shows a dialog for user input and returns false if the dialog is
cancelled. When the dialog method returns false then run() returns and
the plugin terminates.

public void run(String arg){
             if (!showDialog()){
                return;
             }

//otherwise keep executing run()

}

If you hit OK, showDialog() returns true and the plugin continues.

Michael

David William Webster wrote:
> Is there any way to return to ImageJ from a plugin when a potential error

> is detected (e.g. if n input parameter has a bad value.) System.exit()
> kicks me all the way out of ImageJ.
>
> David Webster



______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________