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
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
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 |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | message |
Private subroutine, sets the pointer to the default method to be used when raising exceptions.
Subroutine meant to be publicly called, sets the routine to be used when raising exceptions. Calls the initialisation routine if not already done.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
procedure(raise) | :: | method | subroutine to be used when an exception is raised |
Raises an exception with a given message. By default, exceptions terminate program execution. Calls the initialisation routine if not already done.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | msg | message to be used when an exception is raised |
Workflow that is executed by default when an exception is raised. The argument message is printed to the console and program execution is terminated.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | msg | message to print to the console when exception is raised |