Print error with cause chain and stack trace to specified unit If unit not specified, prints to stdout
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(error_t), | intent(in) | :: | self | |||
| integer(kind=default_int), | intent(in), | optional | :: | unit |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=default_int), | private | :: | i | ||||
| integer(kind=default_int), | private | :: | out_unit |
subroutine error_print_trace(self, unit) !! Print error with cause chain and stack trace to specified unit !! If unit not specified, prints to stdout class(error_t), intent(in) :: self integer(default_int), intent(in), optional :: unit integer(default_int) :: out_unit, i out_unit = stdout if (present(unit)) out_unit = unit if (.not. self%has_error()) return ! Top-level error with named code write (out_unit, '(A)', advance='no') code_to_string(self%code)//": " if (allocated(self%message)) then write (out_unit, '(A)') trim(self%message) else write (out_unit, '(A)') "(no message)" end if ! Cause chain do i = self%cause_depth, 1, -1 write (out_unit, '(A)', advance='no') " Caused by: "//trim(code_to_string(self%cause_codes(i)))//": " write (out_unit, '(A)') trim(self%cause_messages(i)) end do ! Stack trace if (self%stack_depth > 0) then write (out_unit, '(A)') "Call stack (most recent first):" do i = self%stack_depth, 1, -1 write (out_unit, '(A,I0,A)', advance='no') " [", i, "] " write (out_unit, '(A)') trim(self%call_stack(i)) end do end if end subroutine error_print_trace