home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 196.lha / Exception_v0.6 / excption.man < prev    next >
Text File  |  1988-12-27  |  26KB  |  924 lines

  1.      
  2.                           EXCEPTION HANDLING ROUTINES
  3.                                         
  4.                                   _______ _ _                                   Version 0.6
  5.                                  July 6th, 1988
  6.                                         
  7.                                  Gerald T HEWES
  8.                                46 Blvd Inkermann
  9.                                92220 NEUILLY S/S
  10.      FRANCE 
  11.      
  12.                                  I INTRODUCTION
  13.      
  14.         The purpose of this module is to provide a programmer with a set of 
  15.      easy to  use  routines  to  handle error conditions.  The principle of
  16.      exception  handling  is  inspired  from  Ada(r)  exception   routines.
  17.      Exception  handling helps to solve difficult error handling conditions
  18.      such as No more memory, file not open, read/write error....    Usually
  19.      because of the difficulty of handling these errors, not much action is 
  20.      done to  correct them.  How many programmers faithfully test all their
  21.      fread or fwrite results for possible errors?  
  22.      
  23.         Exception may be used by any program either as a  flow  control  or
  24.      either  to  capture  software  errors  i.e 68000 exceptions and Traps.
  25.      Exception makes the usage of traps very easy from C, since no assembly 
  26.      code is required.  
  27.      
  28.         Experienced programmers might not find anything  really  new  about
  29.      these  routines  and  may have already adopted ways to deal with error
  30.      handling but I feel it might help recent Amiga programmers and anybody 
  31.      who is not  interested  in  wrinting  for  the  (n+1)th  time  similar
  32.      procedures.  
  33.      
  34.         These routines  are very different from the GOMF software.  You may
  35.      have as many "protected code" zones in your program as you  want,  and
  36.      you  dispose of a mean to propagate easily errors upward if you cannot
  37.      fix the problem at a low level (usually the case for fwrites's).    In
  38.      any case, no actions are taken whatsoever, control is simply passed to 
  39.      your local  (context  wise)  handling  routine.    Your  task  is  not
  40.      suspended.   All  your  handling  routines  are  in  user  mode   with
  41.      multitasking enabled.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.                                      - 0 -
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      1.2 Contents 
  71.      
  72.      I   INTRODUCTION
  73.      
  74.      II  EXCEPTION HANDLING
  75.      
  76.           2.1 Introduction to Exception Handling
  77.            2.1.1 Top Level
  78.            2.1.2 Resource Protection
  79.           2.2 How to Use Excption
  80.            2.2.1 ExcpGlobal
  81.            2.2.2 MAIN
  82.            2.2.3 ExcpDeclare
  83.            2.2.4 BEGIN/EXCEPTION/END
  84.            2.2.5 Variables
  85.            2.2.6 Excption Class Numbers
  86.           2.3 Important Data
  87.      
  88.      III ORGANISATION
  89.      
  90.           3.1 Files
  91.           3.2 Macros
  92.      
  93.      IV  IMPROVEMENTS
  94.      
  95.      V   CONCLUSION
  96.      
  97.      VI  BIBLIOGRAPHY
  98.      
  99.      
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.                                      - 1 -
  131.  
  132.  
  133.  
  134.  
  135.  
  136.                              II EXCEPTION HANDLING
  137.      
  138.      2.1 Introduction to Exception Handling 
  139.      
  140.         Error  Management  and  complexe  human  interfaces  are  always  a
  141.      difficult problem in  a  program,  and  no  perfect  solution  exists.
  142.      Exception  handling  is one way to alleviate the problem, but does not
  143.      solve it.    These  techniques  were  originally  applied  on  a   sun
  144.      workstation for  an  interactive  program.   Port was then done on the
  145.      Amiga, with a better interface.  Originally,  the  ideas  commes  from
  146.      Ada's(r)  exception  handling  but  has been slightly modified to take
  147.      into account C's differences.   A  first  difference  is  the  use  of
  148.      Macros,  these  do  not have the power of defined keywords in Ada. The
  149.      second major difference stems from the fact that Ada(r)  protects  you
  150.      from  every  error  condition  possible,  while this library will only
  151.      recuperate     errors     which     normally     give     birth     to
  152.      "SoftWare Error/Task Held".  Thus  you still enjoy fireworks for fatal
  153.      errors destroying the operation of the system.  
  154.      
  155.         What is exactly exception programing?  In gross  terms,  algorithms
  156.      usually describe  the  normal  flow  of  operations.    Unfortunately,
  157.      exceptional activities can happen and have to be treated.  If  nothing
  158.      is  provided  by  the  language,  the programmer has to introduce many
  159.      control statements to take into  account  these  abnormal  conditions.
  160.      The  programer  usually  ends  up  with  a  code twice the size of the
  161.      original algorithm.  This has two inconvenients: the code is no longer 
  162.      clear because of the overhead, and it is hard to follow the flow of  a
  163.      normal program.    Exception  programing  tries to solve this problem.
  164.      The principle is clear, write the normal code, and add at the  end  of
  165.      this code  the  code  describing  those exceptional events.  Each part
  166.      being separate, programs get much clearer.  
  167.      
  168.         Lets consider a  simple  problem.    You  want  to  translate  from
  169.      cartesian coordinates  to  polar coordinates.  The method in the first
  170.      quadrant is theta = atan (y/x). This formula is true for x <> 0, if  x
  171.      = 0, then theta = pi/2.  With no exceptions this gives: 
  172.      
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.                                      - 2 -
  197.  
  198.  
  199.  
  200.  
  201.  
  202.         if (x != 0)
  203.          {
  204.            z     =  y/x;
  205.            theta = atan(z);
  206.          }
  207.         else
  208.          theta = pi/2;
  209.      
  210.         The normal  flow is lost in the if condition.  Exception programing
  211.      would prefer: 
  212.      
  213.      ADA:
  214.        begin
  215.         z     := y/x;
  216.         theta := atan(z);
  217.        exception
  218.         when NUMERIC_ERROR =>
  219.          theta = pi/2;
  220.         when others =>
  221.          PUT("UNKNOWN ERROR");
  222.          raise ERROR;
  223.        end;
  224.      
  225.      This is simply translated into:
  226.      
  227.      C:
  228.        BEGIN
  229.         {
  230.          z     = y/x;
  231.          theta = atan(z);
  232.         }
  233.        EXCEPTION
  234.         {
  235.         switch(Eclass)
  236.          {
  237.           case ZERO_DIVIDE   : theta = pi/2; break;
  238.           default            : puts("UNKNOWN ERROR"); RAISE(ERROR);
  239.          }
  240.         }
  241.        END;
  242.      
  243.      
  244.         This may not seem remarkable on a simple example, but it can become 
  245.      very handy in real life problems which usually  are  not  coded  in  6
  246.      lines.  
  247.      
  248.         The idea is simple.  In a protected region, you describe the simple 
  249.      algorithm.  Automatic errors, or software detected ones can provoke an 
  250.      "Exception"  which  will  cause  the  program to abandon the protected
  251.      region to execute the handler region instead.  Either this handler  is
  252.      qualified  to handle the exception and thus controls resumes after the
  253.      protected/handler block, or the handler can decide  to  propagate  the
  254.      exception to the next handler.  
  255.      
  256.         This is  the  second  advantage of Exception programing.  Protected
  257.      blocks can be inscribed inside each other  like  russian  dolls.    An
  258.      exception  can  thus  be  handled,  at  the most convenient level, and
  259.      necessary action while "poping" out can be performed, like  liberating
  260.  
  261.  
  262.                                      - 3 -
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      some resources allocated in the normal flow.  
  269.      
  270.         This   is  why  Exception  handling  is  very  practical  in  riche
  271.      environments like the amiga.  For example, you  can  isolate  all  the
  272.      function calls  in  your  main  Wait  loop with a protection zone.  If
  273.      anything happens, including an abort request, control resumes back  to
  274.      your main  loop  where you can decide what to do.  Thus your main Wait
  275.      loop can be seen as a "top level" for your  program.    Deep  in  your
  276.      code,  if  you  get  stuck,  a  raise  to  the  "top  level" is always
  277.      available.  
  278.      
  279.        Here are a few possible scenarios: 
  280.      
  281.      2.1.1 Top Level 
  282.      
  283.         forever
  284.          {
  285.            Wait();
  286.             if (EXIT) break;
  287.            BEGIN
  288.             {
  289.              switch() { Some Dangerous Functions }
  290.             }
  291.            EXCEPTION
  292.             {
  293.              switch(Eclass) { .... }
  294.             }
  295.            END
  296.          }
  297.      
  298.      2.1.2 Resource Protection 
  299.      
  300.         In this construction, you cannot leave the area without  liberating
  301.      your resource, even if the error will be handled at higher level.  
  302.      
  303.         Allocate-Resource
  304.      
  305.         BEGIN
  306.          {
  307.            Use-Resource (Dangerous Area)
  308.            Liberate-Resource
  309.          }
  310.         EXCEPTION
  311.          {
  312.            Yell
  313.            Liberate-Resource
  314.            Propagate-Error-If-Necessary
  315.          }
  316.         END
  317.      
  318.      2.2 How to Use Excption 
  319.      
  320.         In  order  to  use  all the exception handling routines you need to
  321.      include the following file: 
  322.      
  323.      #include "local:excption.h" 
  324.      
  325.         For examples of the use of the exception handler  consult  the  two
  326.  
  327.  
  328.                                      - 4 -
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      supplied examples "essai.c" and "fact.c".  
  335.      
  336.      2.2.1 ExcpGlobal 
  337.      
  338.         This static  definition is needed once in your code.  It reserves a
  339.      structure needed by the handling  code  to  operate.    ExcpGlobal  is
  340.      implemented as a macro.  
  341.      
  342.      2.2.2 MAIN 
  343.      
  344.         The  first  protected  block,  called throughout this document "top
  345.      level block" is of a particular form.  This  block  does  not  need  a
  346.      declaration  statement  of  the form ExcpDeclare, all relevant data is
  347.      already declared in the ExcpGlobal structure.  The format of the first 
  348.      protected is MAIN/EXCEPTION/OUT. The form  BEGIN/EXCEPTION/END  cannot
  349.      be used.    This  is  very  important  because  the MAIN and OUT macro
  350.      perform the necessary initialization and conclusion functions.  
  351.      
  352.         Here is an example: 
  353.        main()
  354.         {
  355.           other declarations ...
  356.      
  357.           some code ...
  358.      
  359.           MAIN
  360.            {
  361.              protected code ...
  362.            }
  363.           EXCEPTION
  364.            {
  365.              Exception handling code ...
  366.            }
  367.           OUT
  368.      
  369.           yet more code ...
  370.      
  371.         }
  372.      
  373.         Note: the toplevel does not need to be in the main function.  
  374.      
  375.      2.2.3 ExcpDeclare 
  376.      
  377.         Declare an exception handling  routine  in  the  current  function.
  378.      This  is  a  macro  which  hides  the  necessary declaration of hidden
  379.      variables.  As such it must be  used  before  any  program  statement.
  380.      Currently only one protected zone may exist in one routine.  
  381.      
  382.      2.2.4 BEGIN / EXCEPTION / END 
  383.      
  384.         Exception  handling  is  based on the notion of protected blocks of
  385.      statements.   In  the  current  implementation,  only  one  block  per
  386.      function is  allowed.    This in practice has not been an handicap and
  387.      may be changed in future releases.  This limitation  only  stems  from
  388.      the  Macros  used,  not  from any limitation by the exception handling
  389.      routines.  The syntax is: 
  390.      
  391.  
  392.  
  393.  
  394.                                      - 5 -
  395.  
  396.  
  397.  
  398.  
  399.  
  400.        toto()
  401.         {
  402.           ExcpDeclare;
  403.           other declarations ...
  404.      
  405.           some code ...
  406.      
  407.           BEGIN
  408.            {
  409.              protected code ...
  410.            }
  411.           EXCEPTION
  412.            {
  413.              Exception handling code ...
  414.            }
  415.           END
  416.      
  417.           yet more code ...
  418.      
  419.         }
  420.      
  421.      In the some code block, nothing is changed, so put your faithful  code
  422.      in this area.  No niceties are provided.  
  423.      
  424.      In  the  protected  code  block,  you  have  acces  to  the  following
  425.      functions: 
  426.      
  427.         RAISE(ExcpClass)     : raise an error.
  428.         BLOW(ExcpClass)      : raise/blow to top level handler.
  429.      
  430.         Control will be transferred to the exception handling block.   Your
  431.      exception will  then be handled by this code.  Either the exception is
  432.      propagated with a RAISE statement to upper levels, or  it  is  handled
  433.      locally.   If  it is handled locally, execution will resume in the yet
  434.      more code area.  If no exception occur in the  protected  code  block,
  435.      control continues normally in the yet more code area.  
  436.      
  437.         These  two  function may also be called from any subroutines called
  438.      in the protected code block.  They may not be called from another task 
  439.      if a task is created in the protected code block.  
  440.      
  441.         A return statement is not allowed in the protected code  area,  and
  442.      the exit function is not recommended.  Long Jumps are not recommended: 
  443.      Exception handling  is  long jumping, stay consistent.  Goto's are not
  444.      allowed to span in or out of the protected  code  block.    All  those
  445.      limitations  come  from the fact that you have to execute the END code
  446.      before leaving the function.   The  END  code,  disables  the  current
  447.      context and  restores  the  previous  (upper)  one.    If  you want to
  448.      LongJmp, you can modify your  code  to  use  instead  the  propagation
  449.      mechanism.  
  450.      
  451.      In  the  handling code block you should test the exceptions and either
  452.      handle them locally, or propagate them upward.  You have access to the 
  453.      same functions: 
  454.      
  455.  
  456.  
  457.  
  458.  
  459.  
  460.                                      - 6 -
  461.  
  462.  
  463.  
  464.  
  465.  
  466.        RAISE(ExcpClass)   : raise an error to the next level
  467.        BLOW(ExcpClass)    : raise/blow to top level handler.
  468.      
  469.         RAISE has the same operation as when employed in the protected code 
  470.      block, but will transfer control to  the  next  (upper)level  handling
  471.      code, raising  the  error.    Once  raised,  there is no way to resume
  472.      processing in the yet more code block.  
  473.      
  474.         The same restrictions apply to the handling code block  as  to  the
  475.      protected block concerning: goto,return,exit,_exit,longjmp,...  
  476.      
  477.      2.2.5 Variables 
  478.      
  479.         The following variables are defined in the Handler routines: 
  480.      
  481.         Eclass    : Exception class of the exception
  482.      
  483.         In  the  exception  handling  zone,  Eclass  contains the exception
  484.      number being treated.  Be sure to check this number because the system 
  485.      may generate numbers that you have not planned for.  For  example  the
  486.      system  traps  all  68000  errors,  Eclass  is then the Trap number as
  487.      defined by Motorola.  This is very useful for program debugging  since
  488.      the code traps bus errors which usually indicate pointer troubles.  
  489.         If you do not handle the error locally, the call RAISE(Eclass) is a 
  490.      must.  By doing this you can correct the exception at a higher level.  
  491.      
  492.      2.2.6 Excption Class Numbers 
  493.      
  494.         All  exceptions  have  an exception class number which serves as an
  495.      identification.  Numbers from 1-65535 are reserved  values  which  may
  496.      not be  used.  Under the current version words 1-1023 are reserved for
  497.      68000 related problems.  Check the values defined  in  excption.h  for
  498.      more information.   This range covers 68000 exception, 68000 traps and
  499.      could cover 68000 interrupts.  Range 1024-2047  are  global  types  of
  500.      error which   are  also  declared  in  exception.h.    Most  of  these
  501.      declarations are inspired from Ada.  
  502.         Range 2048-65535 are reserved for libraries.  These  values  cannot
  503.      be used for an application.  
  504.         Application must use numbers over 65536.  
  505.      
  506.         The  programmer must take great care to avoid using the same number
  507.      for two different exception.  Unfortunately, this has to  be  done  by
  508.      hand.  This is a major difference with Ada. Two, incompatible ways can 
  509.      be used for allocating these exception class numbers.  
  510.      
  511.         The first method is to #define all your exception class numbers, in 
  512.      a fashion  similar to the handler itself.  This is the most simple way
  513.      but has the inconvenience of being dangerous.   Two  exceptions  might
  514.      use the   same  number.    Coherence  has  to  be  maintained  by  the
  515.      programmer.  This method is not recommended for large programs.  
  516.      
  517.         The   second   method   is   to   use   the   allocating   function
  518.      AllocException().   AllocException  returns  a unique exception number
  519.      starting from 65536. This automatically insures the coherence  of  all
  520.      part of  a  large  program.  Its inconvenient is that it requires more
  521.      code from the programmer point of view.  
  522.      
  523.         The current algorithm for allocation is rudimentary.  You can  only
  524.  
  525.  
  526.                                      - 7 -
  527.  
  528.  
  529.  
  530.  
  531.  
  532.      call  AllocException  with  an argument of -1. This means, as for many
  533.      Amiga allocating function, that you have no preference for the  number
  534.      allocated.   Allocation  starts  from  65536, and increments by one at
  535.      every call.  FreeAllocation is for decoration since it  does  nothing.
  536.      I  might consider providing better allocation mechanism in the future,
  537.      but for the moment I see no use for it.  
  538.      
  539.      2.3 Important Data 
  540.      
  541.         I  add  this  paragraph  since  I  do  not  have  the   appropriate
  542.      documentation.  If you catch an error report it.  
  543.      
  544.         When  a  68000 exception occurs, the Amiga OS detects it and treats
  545.      it.  The Excption 68000 number is calculated and pushed  down  on  the
  546.      SSP stack  after  the  usual  exception  frame.  Control is then given
  547.      back, in superuser mode, to the  code  pointed  by  task->tc_TrapCode.
  548.      When  using  the  exception  handling  routines,  this  points  to  my
  549.      assembler EIExcpHandler routine.  
  550.         This routine tests if the code is running on a 68000. If  yes,  the
  551.      SSP  stack  is  corrected  by 6+4 bytes for simple exception, and 14+4
  552.      bytes for bus or address exceptions.  The +4 comes from the Long  Word
  553.      pushed by the Amiga Os.  
  554.         If  the  code  is  running  on  a  68010  or +, operations are very
  555.      different.  The handler,  fetches  the  format  number  at  SSP+8  and
  556.      corrects the SSP by the following values: 
  557.      Values in 16-bit words 
  558.      
  559.                              Format
  560.      
  561.      0   1   2   3   4   5   6   7   8   9   a   b   c   d   e   f
  562.      -------------------------------------------------------------
  563.      4   4   6   0   0   0   0   0  29  10  16  46   0   0   0   0
  564.      
  565.      
  566.         As usual,  4  bytes have to be added to these numbers.  These table
  567.      may be inaccurate since I do not have a good  documentation  on  these
  568.      values.  
  569.         After  correcting  the  SSP stack, the handler passes in User Mode,
  570.      and calls the EIEndHandler (a C function) with  the  exception  number
  571.      (provided by Amiga OS) as sole argument.  
  572.  
  573.  
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.  
  592.                                      - 8 -
  593.  
  594.  
  595.  
  596.  
  597.  
  598.                                 III ORGANISATION
  599.      
  600.      
  601.      3.1 Files 
  602.      
  603.         To   compile   programs  you  need  to  assign  local:  to  contain
  604.      excption.lib, excption.h and boolean.h.  You must have directory named 
  605.      private with the excppriv.h file in it.  Your programs need to include 
  606.      the definition file "local:excption.h".  
  607.      
  608.         As of version 0.4, all  routines  are  compiled  seperately.    For
  609.      Lattice users, these object modules are all joined in the excption.lib 
  610.      lattice library.  To compile your code all you need to do id to add 
  611.      LIB local:excption.lib 
  612.      to your blink command.  Currently the files are organised as follows: 
  613.      
  614.      -excption.h   : file which your code needs to include to use the
  615.                      exception routines.
  616.      -boolean.h    : file included by excption.h
  617.      -excption.lib : library file to use with blink.
  618.      -excption.man : this file
  619.      -excption.doc : documentation on defined functions
  620.      -EI*.c        : source for defined functions
  621.      -excphand.a   : assembler handling routine
  622.      -essai.*      : A good example of use of exceptions
  623.      -fact         : A bad example, for different reasons but instructive.
  624.      -README       : text file describing the contents and the version
  625.                      differences.
  626.      
  627.      3.2 Macros 
  628.      
  629.         This is a resume of the available Macros, Variables and Functions: 
  630.      
  631.      BEGIN        : M start of a protected block
  632.      
  633.      BLOW         : M give control to outmost handler
  634.      
  635.      Eclass       : V exception class
  636.      
  637.      END          : M end of handler block
  638.      
  639.      ExcpAlloc    : F allocate an unique exception class number
  640.      
  641.      ExcpDeclare  : M declare an excption block in a routine
  642.      
  643.      EXCPDISABLE  : M disable processor error handling
  644.      
  645.      EXCPENABLE   : M enable back processor handling (Default Mode)
  646.      
  647.      ExcpFree     : F free an allocated exception class number
  648.      
  649.      ExcpGlobal   : M declare a global structure needed by exception
  650.      
  651.      EXCEPTION    : M end of protected block, beginning of handler
  652.      
  653.      MAIN         : M start of outmost protected block (replaces BEGIN)
  654.      
  655.      OUT          : M end of outmost  protected block (replaces END)
  656.  
  657.  
  658.                                      - 9 -
  659.  
  660.  
  661.  
  662.  
  663.  
  664.      
  665.      RAISE        : M Propagate exception to inmost handler
  666.  
  667.  
  668.  
  669.  
  670.  
  671.  
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.                                      - 10 -
  725.  
  726.  
  727.  
  728.  
  729.  
  730.                                 IV IMPROVEMENTS
  731.      
  732.         The following ideas will be investigated in further releases: 
  733.      
  734.      -Signaling to  the  User  that an 68000 exception has occured.  Useful
  735.      for debugging.  
  736.      
  737.      -Final Catch of 68000 exceptions and user notice at the top level.  
  738.      
  739.      -Provide a mean for the program to call  a  supplied  function  before
  740.      giving control to the local exception handling code 
  741.      
  742.      -Run time library version 
  743.      
  744.      -Stack checking before saving context 
  745.      
  746.      -Tracing of entrance into protected blocks in a debug version.  
  747.      
  748.         Discussing with  some  Ada compilers makers was instructive.  Their
  749.      point of view was that they do not want  exception  handling  to  lose
  750.      time in  normal  operations.    On  the other hand they are willing to
  751.      consecrate a big amount of time to solve  where  the  control  has  to
  752.      resume when  an exception is raised.  This is radically different from
  753.      my implementation with longjmps.  Each BEGIN statement needs  to  save
  754.      the environment which is slow.  When an exception is raised, restoring 
  755.      the environment  is  not  costly.  Those Ada compiler makers have thus
  756.      used a completely different approach.  At compile time they note where 
  757.      each handler is active.  When an exception occurs, the  program  tests
  758.      where the  exception  occured,  and  thus  where to branch.  It is not
  759.      necessary to save the environment at each begin.  To achieve this  you
  760.      need  to  have  exception handling defined in the language, not out of
  761.      it.  Which is best?  
  762.      
  763.         Performances: 
  764.      
  765.         Version 0.5 seemed to have no  bugs.    There  are  two  things  to
  766.      watch.   Bad  bugs  will  crash  the  system, because they destroy the
  767.      environment.  Nothing can be done by software.  The exception  handler
  768.      is fairly safe since its always checks its data coherence, if an error 
  769.      occurs, an  exit(200) or exit(201) is performed.  These two exits have
  770.      always been due to unmatched BEGIN/EXCEPTION/END statements,  even  in
  771.      spots far from where the program stopped.  Check those if this happens 
  772.      to you.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.                                      - 11 -
  791.  
  792.  
  793.  
  794.  
  795.  
  796.                                   V CONCLUSION
  797.      
  798.      
  799.         Exception  programming  is  a  very  powerful  tool,  but should be
  800.      carefully used.  68000 Exceptions should stay exceptional.    Keep  in
  801.      mind  that  an  exception  declaration  in a routine consumes about 40
  802.      bytes in  the  stack.    Recursive  functions  have  to  be  carefully
  803.      examined.   A good knowledge of LongJumping although not necessary can
  804.      help resolve all kinds of conflicts you may run into.  This  code  can
  805.      be  particularly helpful in the debugging period, but is unfortunately
  806.      incompatible with Fred Fish DBUG macros.  In  general,  this  software
  807.      does not like longjmps.  
  808.      
  809.         Because   of   its   similarity  with  Ada(r)  Exception  handling,
  810.      consulting a manual on Ada, and mostly on how  to  use  its  exception
  811.      mechanism is a recommended idea.  
  812.      
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.                                      - 12 -
  857.  
  858.  
  859.  
  860.  
  861.  
  862.                                 VI BIBLIOGRAPHY
  863.      
  864.      * [ADA 83] 
  865.      REFERENCE   MANUAL   FOR   THE   ADA(r)   PROGRAMMING   LANGUAGE   ---
  866.      ANSI/MIL-STD 1815 A 
  867.      * [BEHM 86] 
  868.      NOTES SUR  LE  TRAITEMENT  DES  EXCEPTIONS  ---  Patrick  BEHM,  BULL,
  869.      Louveciennes 
  870.      
  871.      
  872.      
  873.      
  874.      
  875.      
  876.      
  877.      
  878.      
  879.      
  880.      
  881.      
  882.      
  883.      (r)  ADA  is  a registered trademark of the U.S. Government. Ada Joint
  884.      Program Office.  
  885.  
  886.  
  887.  
  888.  
  889.  
  890.  
  891.  
  892.  
  893.  
  894.  
  895.  
  896.  
  897.  
  898.  
  899.  
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.                                      - 13 -
  923.  
  924.