FUTILS
Some basic Fortran Utilities
Loading...
Searching...
No Matches
Error Handling

< Back to main page

The error_handling_m module provides error handling routines bound to a static type, error_handling.


error_handling%assert_routine

Causes an ERROR STOP, printing an error message, as well as the file name and line number where the error occurred.

The assert routine should be used for internal validity checks only. It is a safety mechanism to ensure that program bugs are found and fixed, with the idea that the code developer uses the file name and line number to inspect the source location where the assertion failure occurred and determine the cause. If you want to ERROR STOP as a result of invalid/improper input parameters, use the abort routine, with a useful error message.

Parameters
[in]condition(logical) : Logical condition to assert
[in]condition_str(character) : The condition as a string
[in]line(integer) : Line number where the assertion is made
[in]file(character) : Name of file where the assertion is made
Note
The futils.h header file provides a macro to automatically insert the file name and line number where the assert routine was called from:
#include 'futils.h'
call error_handling%assert(x > 0 .and. x <= 10)
This is the intended use of the assert routine. It will stop the program if the condition is not satisfied, and print a message including the condition in character form.


error_handling%abort_routine

Causes an ERROR STOP, printing an error message, as well as the file name and line number where the error occurred.

The abort routine should be kept for situations where the assert routine is not appropriate.

Parameters
[in]line(integer) : Line number where the error occurred
[in]file(character) : Name of file where error occurred
[in]msg(character) : Error message
Note
The futils.h header file provides a macro to automatically insert the file name and line number where the abort routine was called from:
#include 'futils.h'
call error_handling%abort('Error message')
This is the intended use of the abort routine. One should only call the underlying error_handling%abort_routine in special cases. One such special case is when you want to specify the line number and file name of an input file to inform the user of invalid input.