13!:0 ]2 Error Capture |
initial writing: 2000-08-02 last updated: 2004-10-26 |
STACK_ERROR_INFO_base_=: (13!:11 ; 13!:12 ; 13!:13 ; 18!:5) ''capturing the error number, error text, stack info, and current locale name. The stack is then cleared, and execution goes into immediate execution.
foo=: 4 : 0 t=. 6!:0 '' x. plus y. ) plus=: 17&|@+ 13!:0 ]2 8 foo 'boo boo' STACK_ERROR_INFO +-+------------------------------+-------------------------------------------- ... |3||domain error: plus |plus[:0] |+----+-+-+-+-------------------------------- ... | | ||plus|3|0|3|17amp;|@+ ... | | || | | | | ... | | || | | | | ... | | |+----+-+-+-+-------------------------------- ... | | ||foo |0|1|3|4 : 0 t=. 6!:0 '' x. plus y. ) ... | | || | | | | ... | | || | | | | ... | | || | | | | ... | | || | | | | ... | | || | | | | ... | | || | | | | ... | | |+----+-+-+-+-------------------------------- ... +-+------------------------------+-------------------------------------------- ... q=: STACK_ERROR_INFO_base_ $q 4 $&.>q ++--+---++ ||30|2 8|| ++--+---++ >0{q 3 >1{q |domain error: plus |plus[:0] 0 2 4 6 7{"1 >2{q +----+-+--------------------------------+-----------+---------------------------+ |plus|0|17&|@+ |+-+-------+| | | | | ||8|boo boo|| | | | | |+-+-------+| | +----+-+--------------------------------+-----------+---------------------------+ |foo |1|4 : 0 t=. 6!:0 '' x. plus y. )|+-+-------+|+--+----------------------+| | | | ||8|boo boo|||t |2000 11 30 9 21 54.811|| | | | |+-+-------+|+--+----------------------+| | | | | ||x.|8 || | | | | |+--+----------------------+| | | | | ||y.|boo boo || | | | | |+--+----------------------+| +----+-+--------------------------------+-----------+---------------------------+Example 1: The latent expression (9!:29), executed on return to immediate execution, can be used to capture any stack error information.
errcap=: 3 : 0 (3!:1 STACK_ERROR_INFO_base_) 1!:2 <":6!:0 '' 1!:2&2 'STACK_ERROR_INFO written to file' ) 9!:27 'i.0 [ errcap 0' NB. set latent expression 3 foo 'boo boo' [ 9!:29 ]1 NB. enable latent expression STACK_ERROR_INFO written to file