Page 1 of 1

How to trap the last error Message

Posted: Sun Aug 29, 2010 9:59 pm
by PGilbert
In a function you could get an error cause by APL or by .Net, how do you differenciate between the 2 when you want to report the error by using :Trap 0 for exemple ? If you do ⎕EXCEPTION.Message when its empty you get a VALUE ERROR and ⎕DM may not be empty when the error comes from .Net because of a previous error.

Thanks,

Pierre Gilbert

Re: How to trap the last error Message

Posted: Mon Aug 30, 2010 2:22 am
by paulmansour
I think []EN should be 90 after a .NET error, and something else otherwise, which should to the trick, unless I am missing something, which I probably am.

Re: How to trap the last error Message

Posted: Tue Aug 31, 2010 1:02 am
by PGilbert
Thanks Paul, here is what works for me. If someone has made something more complete and would like to share...

Code: Select all

 r←GetLastError
 ⍝ Return the Last Error

 :If 90=⎕EN
     r←'EXCEPTION: ',⎕EXCEPTION.Message
 :Else
     r←(1⊃⎕DM),': ',{(~(∧\' '=⍵)∨(⌽∧\⌽' '=⍵))/⍵}(2⊃⎕DM)
 :EndIf


Pierre Gilbert