home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / EFFO / pd6.lzh / TST / exceptions.tst < prev    next >
Text File  |  1989-12-23  |  2KB  |  83 lines

  1. .( Loading Exceptions test...) cr
  2.  
  3. ( Should be used in interactive mode only
  4.  
  5. #include multi_tasking.f83
  6.  
  7. multi-tasking exceptions forth definitions
  8.  
  9. .( 1: Low level errors generated by hardware) cr
  10. 10 0 /                                 ( Try some real errors)
  11. 0 @                                    ( Divide by zero, seg. violation)
  12. 1198203980 @                           ( and bus error. All on a SUN-3/60)
  13.  
  14. .( 2: Example of simulating low level errors, i.e., signals) cr
  15. 3 raise                                        ( Simulates a quit signal)
  16. 5 raise                                        ( and a trace trap signal)
  17. 0 raise                                        ( and an input package error)
  18.  
  19. .( 3: Example of user defined errors types, i.e., exceptions) cr
  20. exception zero-divide                  ( User defined exception)
  21. zero-divide raise                      ( And default error message)
  22.  
  23. .( 4: Example showing that the errors are only local to a task) cr
  24. 0 SEMAPHORE synch
  25.  
  26. 100 100 task.type FOO
  27. task.body
  28.   ." Task#" running @ . ." scheduled" cr
  29.   synch wait
  30.   10 0 /
  31.   ." You shouldn't receive this message" cr
  32. task.end
  33.  
  34. FOO foo
  35.  
  36. 100 100 task.type FIE
  37. task.body
  38.   ." Task#" running @ . ." schedule" cr
  39.   synch wait
  40.   zero-divide raise
  41.   ." You shouldn't receive this message" cr
  42. task.end
  43.  
  44. FIE fie
  45.  
  46. who
  47. synch signal                           ( Signal to the tasks to continue)
  48. synch signal
  49. who                                    ( Show that they are terminated)
  50.  
  51. .( 5: Forth level exception block definition examples) cr
  52.  
  53. .( 5.1: Example of transformation of signal to exception) cr
  54. : div ( x y -- q)
  55.   /
  56. exception> ( x y signal -- )
  57.   drop zero-divide raise ;             ( Transform signal to an exception)
  58.  
  59. 10 0 div
  60.  
  61. .( 5.2: Example of user level messages) cr
  62. : divide ( x y - )
  63.   div
  64. exception> ( x y signal -- )
  65.   abort" divide: you shouldn't divide by zero" ;
  66.  
  67. 10 0 divide cr
  68.  
  69. .( 5.3: Example of a retry expection handling) cr
  70. : divide ( x y -- )
  71.   div
  72. exception> ( x y exception -- )
  73.   case
  74.     zero-divide of 1+ recurse endof
  75.     raise
  76.   endcase ;
  77.  
  78. 10 0 divide . cr
  79.  
  80. )
  81.  
  82. forth only
  83.