Independent error-storing and reporting type,
using the __FILE__ and __LINE__ pre-processor macros.
To use t_err2, first initialise it:
type( t_err2 ), pointer :: bugs=>null()
! initialise
bugs => t_err2()
When an error is captured somewhere, set a message and location as:
! here some error occurs, which gives a nonzero error code
ierr = some_error()
if( ierr /= 0 ) then
! set the error message and location to t_err2:
call bugs% err_set( ierr, __FILE__, __LINE__, msg="error msg", msg_arr=[words] )
return
end if
When you wish to report the stored error message:
if( ierr /= 0 ) then
! error code has been propagated down to some routine (i.e. main), now output it
call bugs% err_write( __FILE__, __LINE__ )
end if
If you wish to add intermediate caller routines to the message:
! an intermediate routine captured the ierr code, and passed it to caller
ierr = something_that_passed_error()
if( ierr /= 0 ) then
! set current location into list of callers
call bugs% err_caller( __FILE__, __LINE__ )
return
end if
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(t_err2), | intent(inout) | :: | self |
set an error message at the location where error occured
set the information about an error. This should be called when an error is first encountered.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(t_err2), | intent(inout) | :: | self | |||
| integer, | intent(in) | :: | ierr | |||
| character(len=*), | intent(in) | :: | file | |||
| integer, | intent(in) | :: | linenr | |||
| character(len=*), | intent(in), | optional | :: | msg |
single-string error message |
|
| character(len=*), | intent(in), | optional | :: | msg_arr(:) |
array of words to be added at end of error message |
add a caller to the list of callers after an error
add a caller to list of callers
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(t_err2), | intent(inout) | :: | self | |||
| character(len=*), | intent(in) | :: | file | |||
| integer, | intent(in) | :: | linenr |
output the error message of currntly recevied error
output the error info to screen. If fileunit is provided, the unit should be open for writing. If fileunit is not provided, output to screen.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(t_err2), | intent(inout) | :: | self | |||
| character(len=*), | intent(in) | :: | file | |||
| integer, | intent(in) | :: | linenr | |||
| integer, | intent(in), | optional | :: | fileunit |
output fileunit |
|
| logical, | intent(in), | optional | :: | kill |
if |
check if an error is present or not
Check if an error is present or not.
On output, ierr has value of error present in the module, and 0 otherwise
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(t_err2), | intent(inout) | :: | self | |||
| integer, | intent(out) | :: | ierr |
reset the variables of this class
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(t_err2), | intent(inout) | :: | self |