home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_std / exceptions.e < prev    next >
Text File  |  1999-06-05  |  4KB  |  149 lines

  1. -- This file is  free  software, which  comes  along  with  SmallEiffel. This
  2. -- software  is  distributed  in the hope that it will be useful, but WITHOUT 
  3. -- ANY  WARRANTY;  without  even  the  implied warranty of MERCHANTABILITY or
  4. -- FITNESS  FOR A PARTICULAR PURPOSE. You can modify it as you want, provided
  5. -- this header is kept unaltered, and a notification of the changes is added.
  6. -- You  are  allowed  to  redistribute  it and sell it, alone or as a part of 
  7. -- another product.
  8. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  9. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  10. --                       http://SmallEiffel.loria.fr
  11. --
  12. class EXCEPTIONS
  13.    --
  14.    -- Facilities for adapting the exception handling mechanism.
  15.    -- This class may be used as ancestor by classes needing its 
  16.    -- facilities.
  17.    --
  18.  
  19. feature -- Various exceptions codes :
  20.  
  21.    Check_instruction: INTEGER is 1;
  22.          -- Exception code for violated check.
  23.  
  24.    Class_invariant: INTEGER is 2;
  25.          -- Exception code for violated class invariant.
  26.  
  27.    Developer_exception: INTEGER is 3;
  28.          -- Exception code for developer exception.
  29.  
  30.    Incorrect_inspect_value: INTEGER is 4;
  31.          -- Exception code for inspect value which is not one
  32.          -- of the inspect constants, if there is no Else_part
  33.  
  34.    Loop_invariant: INTEGER is 5;
  35.          -- Exception code for violated loop invariant
  36.  
  37.    Loop_variant: INTEGER is 6;
  38.          -- Exception code for non-decreased loop variant
  39.  
  40.    No_more_memory: INTEGER is 7;
  41.          -- Exception code for failed memory allocation
  42.  
  43.    Postcondition: INTEGER is 8;
  44.          -- Exception code for violated postcondition.
  45.  
  46.    Precondition: INTEGER is 9;
  47.          -- Exception code for violated precondition.
  48.  
  49.    Routine_failure: INTEGER is 10;
  50.          -- Exception code for failed routine.
  51.  
  52.    Os_signal: INTEGER is 11;
  53.          -- Exception code for a signal received from the OS.
  54.  
  55.    Void_attached_to_expanded: INTEGER is 12;
  56.          -- Exception code for attachment of void value
  57.          -- to expanded entity.
  58.  
  59.    Void_call_target: INTEGER is 13;
  60.          -- Exception code for feature applied to void reference
  61.  
  62. feature
  63.  
  64.    developer_exception_name: STRING is
  65.          -- Name of last developer-raised exception.
  66.       require
  67.          applicable: is_developer_exception
  68.       do
  69.          Result := developer_exception_name_memory.item;
  70.       end;
  71.  
  72.    is_developer_exception: BOOLEAN is
  73.          -- Is the last exception originally due to
  74.          -- a developer exception?
  75.       do
  76.          Result := exception = Developer_exception;
  77.       end;
  78.  
  79.    is_developer_exception_of_name (name: STRING): BOOLEAN is
  80.          -- Is the last exception originally due to a developer
  81.          -- exception of name `name'?
  82.       do
  83.          if is_developer_exception then
  84.             Result := name.is_equal(developer_exception_name);
  85.          end;
  86.       end;
  87.  
  88. feature -- Status report :
  89.  
  90.    assertion_violation: BOOLEAN is
  91.          -- Is last exception originally due to a violated
  92.          -- assertion or non-decreasing variant?
  93.       do
  94.          inspect 
  95.             exception
  96.          when Check_instruction, Class_invariant, Loop_invariant,
  97.               Loop_variant, Postcondition, Precondition then
  98.             Result := true;
  99.          else
  100.          end;
  101.       end;
  102.  
  103.    exception: INTEGER is
  104.          -- Code of last exception that occurred.
  105.       external "SmallEiffel"
  106.       end;
  107.  
  108.    is_signal: BOOLEAN is
  109.          -- Is last exception originally due to an external
  110.          -- event (operating system signal) ?
  111.       do
  112.          Result := signal_number /= 0;
  113.       end;
  114.  
  115. feature -- Basic operations :
  116.  
  117.    die(code: INTEGER) is
  118.          -- Terminate execution with exit status code,
  119.          -- without triggering an exception.
  120.       do
  121.          die_with_code(code);
  122.       end;
  123.  
  124.    raise(name: STRING) is
  125.          -- Raise a developer exception of name name.
  126.       do
  127.          developer_exception_name_memory.set_item(name);
  128.          raise_exception(Developer_exception);
  129.       end;
  130.  
  131. feature -- Non-Standard Extensions :
  132.  
  133.    signal_number: INTEGER is
  134.          -- Signal Number received from OS.  Zero if exception
  135.          -- is not an OS signal.
  136.       external "SmallEiffel"
  137.       end;
  138.  
  139.    developer_exception_name_memory: MEMO[STRING] is
  140.       once
  141.          !!Result;
  142.       end;
  143.  
  144.    raise_exception(code: INTEGER) is
  145.       external "SmallEiffel"
  146.       end;
  147.  
  148. end -- EXCEPTIONS
  149.