error_print_trace Subroutine

private subroutine error_print_trace(this, unit)

Print error with stack trace to specified unit If unit not specified, prints to stdout (unit 6)

Type Bound

error_t

Arguments

Type IntentOptional Attributes Name
class(error_t), intent(in) :: this
integer, intent(in), optional :: unit

Calls

proc~~error_print_trace~~CallsGraph proc~error_print_trace error_t%error_print_trace proc~error_has_error error_t%error_has_error proc~error_print_trace->proc~error_has_error

Variables

Type Visibility Attributes Name Initial
integer, private :: i
integer, private :: out_unit

Source Code

   subroutine error_print_trace(this, unit)
      !! Print error with stack trace to specified unit
      !! If unit not specified, prints to stdout (unit 6)
      class(error_t), intent(in) :: this
      integer, intent(in), optional :: unit
      integer :: out_unit, i

      out_unit = 6  ! stdout
      if (present(unit)) out_unit = unit

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

      ! Print error message
      write (out_unit, '(A,I0,A)', advance='no') "Error ", this%code, ": "
      if (allocated(this%message)) then
         write (out_unit, '(A)') trim(this%message)
      else
         write (out_unit, '(A)') "(no message)"
      end if

      ! Print stack trace if available
      if (this%stack_depth > 0) then
         write (out_unit, '(A)') "Call stack (most recent first):"
         do i = this%stack_depth, 1, -1
            write (out_unit, '(A,I0,A)', advance='no') "  [", i, "] "
            write (out_unit, '(A)') trim(this%call_stack(i))
         end do
      end if
   end subroutine error_print_trace