Can you do try-catch in GUI for .NET?

Posted by jquerijero on 17-Jul-2009 17:20

I need to call System.Diagnostics.Process:Start(...) which can throw an exception. I need to display user-friendly message when that happens. How do you do it?

All Replies

Posted by Matt Baker on 17-Jul-2009 18:23

ABL has try catch syntax, but it goes inside the block as such:

do:

    

     System.Diagnostics.Process:Start(...)

     catch e as Progress.Lang.Error:

          message e:GetMessage(0) view-as alert-box title "Doh!".

     end catch.

     finally:

          ...

     end finally.

end.

Fixed syntax example

Posted by jquerijero on 20-Jul-2009 08:39

I don't see Exception as part of Progress.Lang. Is that a separate assembly?

Posted by Matt Baker on 20-Jul-2009 08:42

Progress.Lang.Error not Progress.Lang.Exception.

I fixed the example in previous post.

Posted by Admin on 20-Jul-2009 08:43

I believe it's typo in Matt's sample code and I'm pretty sure he was referring to System.Exception.

CATCH ex AS System.Exception:

    MESSAGE ex:GetType():ToString() .

END.

will do. Some of the properies of the Progress.Lang.Error interface have been "added" to the Exception as well (like GetMessage(1) etc.).

Posted by jquerijero on 20-Jul-2009 11:05

It's not catching the exception. Here is the method I defined.

METHOD PUBLIC VOID StartAProcess( INPUT commandName AS CHARACTER ):

     System.Diagnostics.Process:Start(commandName).

     CATCH e AS Progress.Lang.Error:         

          MessageBox:Show(THIS-OBJECT,

          "Cannot find '" + commandName + "'. Make sure the path or Internet address is correct",

          "Error",

          MessageBoxButtons:OK,

          MessageBoxIcon:Error).     

     END CATCH.

END METHOD

Just pass it a gibberish commandName then it should error out.

Posted by sarahm on 20-Jul-2009 11:38

If error is raised from your Start method, then it should be caught by the CATCH for Progress.Lang.Error.  The .NET System.Exception is tooled in the GUI for .NET to implement the PLE interface, so that should work.  It should also work to catch System.Exception, as Mike mentioned.  Did you try that?  If that works, but PLE doesn't, you should report a bug.  Of course if neither of them work you should also report a bug.

I suppose the possibility exists that error is not being raised.  What is the behavior you are seeing?  If you had another executable line after the Start method, would it execute?

Posted by jquerijero on 20-Jul-2009 12:58

It's working now after I Clean and Rebuild the project.

Posted by jquerijero on 29-Jul-2009 17:28

Also when the using the catch for just a portion(in between codes) of the code block, it requires DO ON ERROR UNDO, LEAVE: ... END.

Posted by Admin on 30-Jul-2009 01:54

jquerijero schrieb:

Also when the using the catch for just a portion(in between codes) of the code block, it requires DO ON ERROR UNDO, LEAVE: ... END.

Take it as the "try" block header... You may use other forms of DO ON ERROR UNDO, ... as well, like DO ON ERROR UNDO, THROW.

This thread is closed