ferror 1.4.1
FERROR is a library to assist with error handling in Fortran projects.
Loading...
Searching...
No Matches
ferror

Introduction

FERROR is a library to assist with error handling in Fortran projects. The error handling capabilities also have been extended to be called from C thereby providing both an error handling mechanism for C projects as well as allowing C interop with Fortran projects that use this library to handle errors.

Example
The following piece of code offers a simple introduction to the use of this library.
program example
use ferror
use, intrinsic :: iso_fortran_env, only : int32
implicit none
! Variables
type(errors) :: err_mgr
! Ensure the error reporting doesn't terminate the application. The default
! behavior terminates the application - optional.
call err_mgr%set_exit_on_error(.false.)
! Don't print the error message to the command line. The default behavior
! prints the error information to the command line - optional.
call err_mgr%set_suppress_printing(.true.)
! Call the routine that causes the error
call causes_error(err_mgr)
! Print the error information
print '(A)', "An error occurred in the following subroutine: " // &
err_mgr%get_error_fcn_name()
print '(A)', "The error message is: " // err_mgr%get_error_message()
print '(AI0)', "The error code is: ", err_mgr%get_error_flag()
contains
! The purpose of this subroutine is to simply trigger an error condition.
subroutine causes_error(err)
! Arguments
class(errors), intent(inout) :: err
! Define an error flag
integer(int32), parameter :: error_flag = 200
! Trigger the error condition
call err%report_error(&
"causes_error", & ! The subroutine or function name
"This is a test error message.", & ! The error message.
error_flag) ! The error flag
end subroutine
end program
ferror
Definition: ferror.f90:91
The above program produces the following output.
An error occurred in the following subroutine: causes_error
The error message is: This is a test error message.
The error code is: 200
The above program also creates a log file. The log file is titled error_log.txt by default, but can be named whatever by the user. The contents of the file written from the above program are as follows.
***** ERROR *****
1/2/2018; 16:49:40
Function: causes_error
Error Flag: 200
Message:
This is a test error message.
If additional errors are encountered, the information is simply appended to the end of the file.