How to use ⎕EXCEPTION to show an error

Using (or providing) Microsoft.NET Classes

How to use ⎕EXCEPTION to show an error

Postby PGilbert on Thu Mar 26, 2015 5:54 pm

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
User avatar
PGilbert
 
Posts: 361
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: How to use ⎕EXCEPTION to show an error

Postby PGilbert on Tue Mar 31, 2015 12:35 am

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
User avatar
PGilbert
 
Posts: 361
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: How to use ⎕EXCEPTION to show an error

Postby JohnD|Dyalog on Tue Mar 31, 2015 10:22 am

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.
User avatar
JohnD|Dyalog
 
Posts: 60
Joined: Wed Oct 01, 2008 9:35 am

Re: How to use ⎕EXCEPTION to show an error

Postby PGilbert on Tue Mar 31, 2015 12:31 pm

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,
User avatar
PGilbert
 
Posts: 361
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: How to use ⎕EXCEPTION to show an error

Postby PGilbert on Thu Apr 09, 2015 2:20 pm

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:

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.
User avatar
PGilbert
 
Posts: 361
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada


Return to Microsoft.NET

Who is online

Users browsing this forum: No registered users and 1 guest