Silverfrost Logo About Us | Contact Us
 

TRAP_EXCEPTION@

Platform

Win32

Purpose

Install a user defined exception handler (Win32 only).

Syntax

INTEGER (KIND=3) FUNCTION TRAP_EXCEPTION@(EXCEPTION, ROUTINE)
INTEGER (KIND=3) EXCEPTION, ROUTINE
EXTERNAL ROUTINE

Description

The subroutine ROUTINE is installed as the default method of handling the event specified by EXCEPTION.

Return value

If EXCEPTION is a valid exception event, the location of the previous handler is returned. 0 is returned if EXCEPTION is an invalid exception code.

The values of EXCEPTION are as follows:

Event

Parameter name

Value

Access violation

ACCESS_VIOLATION

0

Invalid floating point operation

FLT_INVALID_OPERATION

1

Denormal floating point operand

FLT_DENORMAL

2

Floating point divide by zero

FLT_DIV_ZERO

3

Floating point overflow

FLT_OVERFLOW

4

Floating point underflow

FLT_UNDERFLOW

5

Inexact floating point result

FLT_INEXACT_RESULT

6

Floating point stack overflow

FLT_STACK_FAULT

7

Breakpoint

BREAK_POINT

9

Single step

SINGLE_STEP

10

Execution of a privileged instruction

PRIV_INSTRUCTION

11

All exceptions

ALL_EXCEPTIONS

12

All floating point exceptions

ALL_FLOATING_POINT

13

Integer divide by zero

INT_DIVIDEBY_ZERO

14

Down to page reserve

DOWNTO_PAGE_RESERVE

16

Values returned by ROUTINE:

Instruction to event handler

Parameter name

Value

Exception has been handled so continue execution.

CONTINUE_EXECUTION

0

The problem has not been fixed so the system should try to handle this event.

EXCEPTION_UNHANDLED

1

Unable to continue after handling this exception so exit from the program.

NONCONTINUABLE_EXCEPTION

-2

 

Notes

Unless assembler coding is used, ROUTINE should normally return the value NONCONTINUABLE_EXCEPTION. One exception to this rule is floating point underflow for which one can return EXCEPTION_UNHANDLED and then continue.

Integer overflow does not generate an exception unless in /DEBUG mode. In /DEBUG mode the exception cannot be trapped.

The above parameter names and values are listed in the file exceptn.ins.

Example

PROGRAM TrapException
  INCLUDE <EXCEPTN.INS>
  INTEGER TRAP_EXCEPTION@, DivZeroHandler, OldHandler
  EXTERNAL TRAP_EXCEPTION@, DivZeroHandler
  REAL r, zero
  OldHandler=TRAP_EXCEPTION@(FLT_DIV_ZERO, DivZeroHandler)
  zero=0.0
  r=1.234/zero
  PRINT *, 'Normal termination'
END
INTEGER FUNCTION DivZeroHandler()
  INCLUDE <EXCEPTN.INS>
  PRINT *, 'Float divide by zero trapped'
  DivZeroHandler= NONCONTINUABLE_EXCEPTION
END

This example illustrates a case where it is not possible to continue executing the program after the event has been trapped. The best that one can do is to save program data and exit cleanly.

 

 

Copyright © 1999-2017 Silverfrost Limited