Throw an exception in the json_core. This routine sets the error flag, and prevents any subsequent routine from doing anything, until json_clear_exceptions is called.
If is_verbose
is true, this will also print a
traceback if the Intel compiler is used.
If stop_on_error
is true, then the program is stopped.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
character(kind=CK,len=*), | intent(in) | :: | msg | the error message |
subroutine json_throw_exception(json,msg)
#ifdef __INTEL_COMPILER
use ifcore, only: tracebackqq
#endif
implicit none
class(json_core),intent(inout) :: json
character(kind=CK,len=*),intent(in) :: msg !! the error message
json%exception_thrown = .true.
json%err_message = trim(msg)
if (json%stop_on_error) then
#ifdef __INTEL_COMPILER
! for Intel, we raise a traceback and quit
call tracebackqq(string=trim(msg), user_exit_code=0)
#else
write(error_unit,'(A)') 'JSON-Fortran Exception: '//trim(msg)
error stop 1
#endif
elseif (json%is_verbose) then
write(output_unit,'(A)') '***********************'
write(output_unit,'(A)') 'JSON-Fortran Exception: '//trim(msg)
!#if defined __GFORTRAN__
! call backtrace() ! (have to compile with -fbacktrace -fall-intrinsics flags)
!#endif
#ifdef __INTEL_COMPILER
call tracebackqq(user_exit_code=-1) ! print a traceback and return
#endif
write(output_unit,'(A)') '***********************'
end if
end subroutine json_throw_exception