exit_code Derived Type

type, public :: exit_code

Type providing an exit code and message text for exit reasons


Contents

Source Code


Components

Type Visibility Attributes Name Initial
integer, private :: code = 0

A numeric exit code used to identify the exit reason.

character(len=exit_string_len), private :: message = "No exit reason specified. Code termination may be unexpected."

A user friendly message explaining the exit reason.


Type-Bound Procedures

procedure, public, :: create_message

Construct the output message describing the exit reason and return as a string

  • private function create_message(self)

    Make a string containing the error code and exit reason. This is kept minimal to make it easier for tests to parse.

    Arguments

    Type IntentOptional Attributes Name
    class(exit_code), intent(in) :: self

    Return Value character(len=exit_string_len)

procedure, public, :: write_exit_file

Ask for the exit reason output message and write to the exit_reason_unit

  • private subroutine write_exit_file(self)

    Write exit file containing exit code and message

    Arguments

    Type IntentOptional Attributes Name
    class(exit_code), intent(in) :: self

procedure, public, :: is_identical

Ask if this instance is identical to another passed exit_code

  • private function is_identical(self, other)

    Determines if a passed exit_code instance is identical to this instance.

    We could imagine providing an operator(==) overload that makes use of this but this may not be well supported by all compilers currently.

    Arguments

    Type IntentOptional Attributes Name
    class(exit_code), intent(in) :: self
    type(exit_code), intent(in) :: other

    Return Value logical

procedure, private :: code_matches_integer

Ask if this instance's code matches the passed value. This can either be another exit_code instance or an integer.

  • private function code_matches_integer(self, code)

    Determines if a passed exit_code instance has the same code as the passed integer.

    Arguments

    Type IntentOptional Attributes Name
    class(exit_code), intent(in) :: self
    integer, intent(in) :: code

    Return Value logical

procedure, private :: code_matches_instance

  • private function code_matches_instance(self, other)

    Determines if a passed exit_code instance has the same code as this instance.

    Arguments

    Type IntentOptional Attributes Name
    class(exit_code), intent(in) :: self
    type(exit_code), intent(in) :: other

    Return Value logical

generic, public, :: code_matches => code_matches_integer, code_matches_instance

  • private function code_matches_integer(self, code)

    Determines if a passed exit_code instance has the same code as the passed integer.

    Arguments

    Type IntentOptional Attributes Name
    class(exit_code), intent(in) :: self
    integer, intent(in) :: code

    Return Value logical

  • private function code_matches_instance(self, other)

    Determines if a passed exit_code instance has the same code as this instance.

    Arguments

    Type IntentOptional Attributes Name
    class(exit_code), intent(in) :: self
    type(exit_code), intent(in) :: other

    Return Value logical

Source Code

  type :: exit_code
     private
     !> A numeric exit code used to identify the exit reason.
     integer :: code = 0
     !> A user friendly message explaining the exit reason.
     character(len=exit_string_len) :: message = "No exit reason specified. Code termination may be unexpected."
   contains
     !> Construct the output message describing the exit reason and return as a string
     procedure :: create_message
     !> Ask for the exit reason output message and write to the [[exit_reason_unit]]
     procedure :: write_exit_file
     !> Ask if this instance is identical to another passed `exit_code`
     procedure :: is_identical
     !> Ask if this instance's code matches the passed value. This can
     !> either be another `exit_code` instance or an integer.
     procedure, private :: code_matches_integer
     procedure, private :: code_matches_instance
     generic :: code_matches => code_matches_integer, code_matches_instance
  end type exit_code