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 >
Encoding:
Text File  |  1988-12-28  |  25.0 KB  |  924 lines

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