mod_exceptions Module

Module to explicitly handle exceptions. Depending on the application at hand we override what happens when an exception is raised, which is useful for testing purposes (no error stop if we expect something to fail). Loosely based on an example given in https://github.com/Goddard-Fortran-Ecosystem/pFUnit_demos/blob/main/Basic/src/throw.F90


Contents


Variables

TypeVisibilityAttributesNameInitial
procedure(raise), private, pointer:: raise_method=> null()

pointer to method that is used to raise exceptions

logical, private, save:: initialised =.false.

logical to check if raise_method pointer is assigned


Abstract Interfaces

abstract interface

  • private subroutine raise(message)

    Arguments

    TypeIntentOptionalAttributesName
    character(len=*), intent(in) :: message

Subroutines

private subroutine initialise_exceptions()

Private subroutine, sets the pointer to the default method to be used when raising exceptions.

Arguments

None

public subroutine set_raise_method(method)

Subroutine meant to be publicly called, sets the routine to be used when raising exceptions. Calls the initialisation routine if not already done.

Arguments

TypeIntentOptionalAttributesName
procedure(raise) :: method

subroutine to be used when an exception is raised

public subroutine raise_exception(msg)

Raises an exception with a given message. By default, exceptions terminate program execution. Calls the initialisation routine if not already done.

Arguments

TypeIntentOptionalAttributesName
character(len=*), intent(in) :: msg

message to be used when an exception is raised

private subroutine on_exception_raised(msg)

Workflow that is executed by default when an exception is raised. The argument message is printed to the console and program execution is terminated.

Arguments

TypeIntentOptionalAttributesName
character(len=*), intent(in) :: msg

message to print to the console when exception is raised