Show how to create a user-defined exception   and   show how to catch an exception raised from several nested calls away.

   Create two user-defined exceptions,   U0   and   U1. 
   Have function   foo   call function   bar   twice.
   Have function   bar   call function   baz. 
   Arrange for function   baz   to raise, or throw exception   U0   on its first call, then exception   U1   on its second.
   Function   foo   should catch only exception   U0,   not   U1.


Show/describe what happens when the program is run.




      REM Allocate error numbers:
      U0& = 123
      U1& = 124
 
      PROCfoo
      END
 
      DEF PROCfoo
      ON ERROR LOCAL IF ERR = U0& THEN PRINT "Exception U0 caught in foo" ELSE \
      \              RESTORE ERROR : ERROR ERR, REPORT$
      PROCbar
      PROCbar
      ENDPROC
 
      DEF PROCbar
      PROCbaz
      ENDPROC
 
      DEF PROCbaz
      PRIVATE called%
      called% += 1
      CASE called% OF
        WHEN 1: ERROR U0&, "Exception U0 thrown"
        WHEN 2: ERROR U1&, "Exception U1 thrown"
      ENDCASE
      ENDPROC
 