t_err2 Derived Type

type, public :: t_err2

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

Constructor

public interface t_err2

  • private function error_constructor() result(this)

    Arguments

    None

    Return Value type(t_err2), pointer


Finalization Procedures

final :: error_destructor

  • private subroutine error_destructor(self)

    Arguments

    Type IntentOptional Attributes Name
    type(t_err2), intent(inout) :: self

Type-Bound Procedures

procedure, public :: err_set => t_err2_err_set

set an error message at the location where error occured

  • private subroutine t_err2_err_set(self, ierr, file, linenr, msg, msg_arr)

    set the information about an error. This should be called when an error is first encountered.

    Arguments

    Type IntentOptional 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

procedure, public :: err_caller => t_err2_err_caller

add a caller to the list of callers after an error

  • private subroutine t_err2_err_caller(self, file, linenr)

    add a caller to list of callers

    Arguments

    Type IntentOptional Attributes Name
    class(t_err2), intent(inout) :: self
    character(len=*), intent(in) :: file
    integer, intent(in) :: linenr

procedure, public :: err_write => t_err2_err_write

output the error message of currntly recevied error

  • private subroutine t_err2_err_write(self, file, linenr, fileunit, kill)

    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.

    Arguments

    Type IntentOptional 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 .true., kill the program via simple stop

procedure, public :: err_present => t_err2_err_present

check if an error is present or not

  • private subroutine t_err2_err_present(self, ierr)

    Check if an error is present or not. On output, ierr has value of error present in the module, and 0 otherwise

    Arguments

    Type IntentOptional Attributes Name
    class(t_err2), intent(inout) :: self
    integer, intent(out) :: ierr

procedure, public :: err_reset => t_err2_err_reset

reset the variables of this class

  • private subroutine t_err2_err_reset(self)

    Arguments

    Type IntentOptional Attributes Name
    class(t_err2), intent(inout) :: self