error_fatal Subroutine

private subroutine error_fatal(self, unit, exit_code)

Print the error trace and stop the program Use for unrecoverable errors

Usage: if (err%has_error()) call err%fatal() if (err%has_error()) call err%fatal(exit_code=2) ! custom status

exit_code is the process exit status, default 1. A non-default status needs F2018 variable stop codes; compilers without them can be built with -DPIC_NO_VARIABLE_STOP_CODE, which always exits 1.

Type Bound

error_t

Arguments

Type IntentOptional Attributes Name
class(error_t), intent(in) :: self
integer(kind=default_int), intent(in), optional :: unit
integer(kind=default_int), intent(in), optional :: exit_code

Calls

proc~~error_fatal~~CallsGraph proc~error_fatal error_t%error_fatal proc~error_has_error error_t%error_has_error proc~error_fatal->proc~error_has_error proc~error_print_trace error_t%error_print_trace proc~error_fatal->proc~error_print_trace proc~error_print_trace->proc~error_has_error proc~code_to_string code_to_string proc~error_print_trace->proc~code_to_string proc~omitted_note omitted_note proc~error_print_trace->proc~omitted_note

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private :: status

Source Code

   subroutine error_fatal(self, unit, exit_code)
      !! Print the error trace and stop the program
      !! Use for unrecoverable errors
      !!
      !! Usage:
      !!   if (err%has_error()) call err%fatal()
      !!   if (err%has_error()) call err%fatal(exit_code=2)  ! custom status
      !!
      !! `exit_code` is the process exit status, default 1. A non-default
      !! status needs F2018 variable stop codes; compilers without them can
      !! be built with -DPIC_NO_VARIABLE_STOP_CODE, which always exits 1.
      class(error_t), intent(in) :: self
      integer(default_int), intent(in), optional :: unit
      integer(default_int), intent(in), optional :: exit_code
#ifndef PIC_NO_VARIABLE_STOP_CODE
      integer(default_int) :: status
#endif

#ifndef PIC_NO_VARIABLE_STOP_CODE
      status = 1
      if (present(exit_code)) status = exit_code
#endif

      if (.not. self%has_error()) return

      call self%print_trace(unit)
#ifdef PIC_NO_VARIABLE_STOP_CODE
      error stop 1
#else
      ! int() puts the stop code in the compiler's default integer kind,
      ! which is what the standard requires even in an int64 PIC build
      error stop int(status)
#endif
   end subroutine error_fatal