home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / pibterm / pibt41s1.arc / ERRORHAN.MOD < prev    next >
Text File  |  1988-02-11  |  7KB  |  155 lines

  1. (*----------------------------------------------------------------------*)
  2. (*     Error_Handler --- Handle program aborts by exiting gracefully    *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. PROCEDURE Error_Handler;
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*     Procedure:  Error_Handler                                        *)
  10. (*                                                                      *)
  11. (*     Purpose:    Handle PibTerm program aborts by halting gracefully  *)
  12. (*                                                                      *)
  13. (*     Calling Sequence:                                                *)
  14. (*                                                                      *)
  15. (*        Error_Handler;                                                *)
  16. (*                                                                      *)
  17. (*     Remarks:                                                         *)
  18. (*                                                                      *)
  19. (*        This routine needs to be cleaned up to handle file closing    *)
  20. (*        better at some point.                                         *)
  21. (*                                                                      *)
  22. (*----------------------------------------------------------------------*)
  23.  
  24. VAR
  25.    I    : INTEGER;
  26.    Mess : AnyStr;
  27.  
  28. (* STRUCTURED *) Const
  29.    Sorry_Mess  : STRING[60]
  30.                  = 'Sorry, there has been a system error, please call back later';
  31.    Discon_Mess : STRING[17]
  32.                  = 'Disconnecting....';
  33.  
  34. BEGIN (* Error_Handler *)
  35.                                    (* Make sure we're in text mode.        *)
  36.    Set_Text_Mode( Text_Mode );
  37.                                    (* Send notice of fatal error (also to  *)
  38.                                    (* caller in host mode) and quit.       *)
  39.    IF ( ExitCode > 0 ) THEN
  40.       BEGIN
  41.  
  42.          IF Host_Mode THEN
  43.             BEGIN
  44.                Async_Send_String(' ');
  45.                Async_Send_String(Sorry_Mess);
  46.                Async_Send_String(Discon_Mess);
  47.                WRITELN;
  48.                WRITELN(Sorry_Mess);
  49.                WRITELN(Discon_Mess);
  50.             END
  51.          ELSE
  52.             BEGIN
  53.                WRITELN;
  54.                WRITELN('Sorry, PibTerm has encountered a serious error.');
  55.             END;
  56.  
  57.                                    (* Report error number *)
  58.  
  59.          IF ( ErrorAddr <> NIL ) THEN
  60.             WRITELN('Error number: ', ExitCode, ' ($',
  61.                     Dec_To_Hex( WORD( ExitCode ) ),
  62.                     ') at address $',
  63.                     Dec_To_Hex( SEG( ErrorAddr^ ) ),':$',
  64.                     Dec_To_Hex( OFS( ErrorAddr^ ) ) );
  65.  
  66.                                    (* Report memory management errors  *)
  67.                                    (* as possibly not enough installed *)
  68.                                    (* memory.                          *)
  69.  
  70.          IF ( ( ExitCode = HeapTooSmall ) OR
  71.               ( ExitCode = StackTooSmall ) ) THEN
  72.             BEGIN
  73.                WRITE  ('This machine does not have enough memory available');
  74.                WRITELN(' to run PibTerm.');
  75.             END
  76.          ELSE IF ( ErrorAddr = NIL ) THEN
  77.  
  78.             CASE ExitCode OF
  79.  
  80.                1: BEGIN
  81.                      CASE OverlayError OF
  82.                         1    :  Mess := 'Insufficient heap space for stack and fixup lists';
  83.                         2    :  Mess := 'OVR file not found';
  84.                         3    :  Mess := 'OVERLAY has not been run on the EXE file';
  85.                         4    :  Mess := 'OVR file invalid format';
  86.                         5,
  87.                         $200 :  Mess := 'Error reading overlay file';
  88.                         6,
  89.                         $300 :  Mess := 'Error accessing expanded memory';
  90.                         7    :  Mess := 'Too many relocation items in the OVR file';
  91.                         $100 :  Mess := 'Out of overlay stack space';
  92.                         ELSE Mess := 'Overlay error';
  93.                      END (* CASE *);
  94.                      WRITELN( Mess );
  95.                   END;
  96.  
  97.                2: BEGIN
  98.                      WRITELN('Set Block error on return from DOS, PibTerm cannot continue.');
  99.                      WRITELN('You will probably need to re-boot.');
  100.                   END;
  101.  
  102.                3: BEGIN
  103.                      WRITELN('PibTerm cannot initialize communications.');
  104.                      WRITELN('The serial port you specified cannot be accessed.');
  105.                      WRITELN('Make sure that you have specified the correct serial');
  106.                      WRITELN('port number in the PIBTERM.CNF file, or use the');
  107.                      WRITELN('/P=portnumber parameter when invoking PibTerm to');
  108.                      WRITELN('override the port indicated by PIBTERM.CNF.');
  109.                      WRITELN('For example, type');
  110.                      WRITELN('     PIBTERM /P=2');
  111.                      WRITELN('to use serial port 2 regardless of what port is');
  112.                      WRITELN('specified in PIBTERM.CNF.');
  113.                   END;
  114.  
  115.                ELSE;
  116.  
  117.             END (* CASE *);
  118.  
  119.       END;
  120.                                    (* Close down all program facilities *)
  121.    FiniTerm;
  122.  
  123.    WRITELN;
  124.    WRITELN('PibTerm execution stopped ... ');
  125.    DELAY  ( Three_Second_Delay    );
  126.  
  127.                                    (* Restore old handler *)
  128.    ExitProc  := ExitSave;
  129.    ErrorAddr := NIL;
  130.  
  131.    Error_Exit_Taken := TRUE;
  132.  
  133.    Halt( ErrorEnd );
  134.  
  135. END   (* Error_Handler *);
  136.  
  137. (*----------------------------------------------------------------------*)
  138. (*     Heap_Error_Handler --- Handle heap request errors                *)
  139. (*----------------------------------------------------------------------*)
  140.  
  141. FUNCTION Heap_Error_Handler( Size : WORD ) : INTEGER;
  142.  
  143. (*----------------------------------------------------------------------*)
  144. (*                                                                      *)
  145. (*     Function:   Heap_Error_Handler                                   *)
  146. (*                                                                      *)
  147. (*     Purpose:    Handle heap overflow errors.                         *)
  148. (*                                                                      *)
  149. (*----------------------------------------------------------------------*)
  150.  
  151. BEGIN (* Heap_Error_Handler *)
  152.  
  153.    Heap_Error_Handler := 1;
  154.  
  155. END   (* Heap_Error_Handler *);