How to use ⎕EXCEPTION to show an error
5 posts
• Page 1 of 1
How to use ⎕EXCEPTION to show an error
Currently we are using the expression error←⎕EXCEPTION.Message to trap the error message coming from .Net. This is working most of the times. However it will happen sometimes that there is no message coming from .Net and the expression error←⎕EXCEPTION.Message will generate a VALUE ERROR inside the :Trap and we have to do a another :Trap to catch it.
Is there a better way to do this ?
Regards,
Pierre Gilbert
Is there a better way to do this ?
Regards,
Pierre Gilbert
-
PGilbert - Posts: 440
- Joined: Sun Dec 13, 2009 8:46 pm
- Location: Montréal, Québec, Canada
Re: How to use ⎕EXCEPTION to show an error
For the benefits of everybody here is the code to trap ⎕EXCEPTION that we are using. If somebody has a better idea please let us know:
- Code: Select all
:Trap 0
⍝ somecode here
:Else
⍝ Build the Error Message
:If 90≠⎕EN
⍝ APL Error
error←(1⊃⎕DM),': ',{(' '=1↑⍵)↓((1↓a,0)∨a←' '≠⍵)/⍵}(2⊃⎕DM),(⎕UCS 13)
:Else
⍝ .Net Error
:Trap 0
⍝ Show the value of ⎕EXCEPTION.Message if not ⎕NULL.
error←('EXCEPTION: ',⎕EXCEPTION.Message),(⎕UCS 13)
:Else
⍝ Sometimes ⎕EXCEPTION is (NULL) and will bug here.
error←'EXCEPTION: Unknown error',(⎕UCS 13)
:EndTrap
:End
:EndTrap
-
PGilbert - Posts: 440
- Joined: Sun Dec 13, 2009 8:46 pm
- Location: Montréal, Québec, Canada
Re: How to use ⎕EXCEPTION to show an error
Hello Pierre,
The only case we are aware of where this can happen is with an EXCEPTION raised from a WPF GUI when there is no .NET code on the stack.
This generally happens if you interact with the GUI without having called one of the modal WPF functions, such as, Application.Run or Window.ShowDialog. If you've not called one of these modal functions and WPF generates an exception then the interpreter has no way of catching the exception, or retrieving the message.
If you are seeing this problem somewhere else, and can generate a repro, we'd be happy to take a look.
Best Regards,
John Daintree.
The only case we are aware of where this can happen is with an EXCEPTION raised from a WPF GUI when there is no .NET code on the stack.
This generally happens if you interact with the GUI without having called one of the modal WPF functions, such as, Application.Run or Window.ShowDialog. If you've not called one of these modal functions and WPF generates an exception then the interpreter has no way of catching the exception, or retrieving the message.
If you are seeing this problem somewhere else, and can generate a repro, we'd be happy to take a look.
Best Regards,
John Daintree.
-
JohnD|Dyalog - Posts: 74
- Joined: Wed Oct 01, 2008 9:35 am
Re: How to use ⎕EXCEPTION to show an error
Hello John, you are correct with your assessment. It is happening often when using 3rd party dll like Syncfusion. If the dll throw an exception while the code to build the Window is executing and we are still before the call to .ShowDialog, it may or may not be empty. I will gather some reproducible cases and email them to Vince.
Thanks,
Thanks,
-
PGilbert - Posts: 440
- Joined: Sun Dec 13, 2009 8:46 pm
- Location: Montréal, Québec, Canada
Re: How to use ⎕EXCEPTION to show an error
Hello John again, I have resolve my problem with your help. Looks like the empty ⎕EXCEPTION.Message were generated when using the .Show method while in development mode. When using .ShowDialog there is always a value in ⎕EXCEPTION.Message, thanks for your explanations on that.
I have found a way to test if ⎕EXCEPTION.Message is empty without using a :Trap statement: '(NULL)'≢⍕⎕EXCEPTION . So the previous code would look like this now:
Thanks again for your help.
I have found a way to test if ⎕EXCEPTION.Message is empty without using a :Trap statement: '(NULL)'≢⍕⎕EXCEPTION . So the previous code would look like this now:
- Code: Select all
:Trap 0
⍝ somecode here
:Else
⍝ Build the Error Message
:If 90≠⎕EN
⍝ APL Error
error←(1⊃⎕DM),': ',{(' '=1↑⍵)↓((1↓a,0)∨a←' '≠⍵)/⍵}(2⊃⎕DM),(⎕UCS 13)
:Else
⍝ .Net Error
:If '(NULL)'≢⍕⎕EXCEPTION
⍝ Show the value of ⎕EXCEPTION if not (NULL).
error←('EXCEPTION: ',⎕EXCEPTION.Message),(⎕UCS 13)
:Else
⍝ If ⎕EXCEPTION is (NULL) than the .Message property will generate a VALUE ERROR
error←'EXCEPTION: Unknown error',(⎕UCS 13)
:EndIf
:End
:EndTrap
Thanks again for your help.
-
PGilbert - Posts: 440
- Joined: Sun Dec 13, 2009 8:46 pm
- Location: Montréal, Québec, Canada
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 0 guests
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group