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?
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
I don't see Exception as part of Progress.Lang. Is that a separate assembly?
Progress.Lang.Error not Progress.Lang.Exception.
I fixed the example in previous post.
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.).
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.
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?
It's working now after I Clean and Rebuild the project.
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.
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.