json_throw_exception Subroutine

private subroutine json_throw_exception(json, msg)

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.


Type IntentOptional AttributesName
class(json_core), intent(inout) :: json
character(kind=CK,len=*), intent(in) :: msg

the error message


Source Code

Source Code

    subroutine json_throw_exception(json,msg)

    use ifcore, only: tracebackqq

    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

        ! for Intel, we raise a traceback and quit
        call tracebackqq(string=trim(msg), user_exit_code=0)
        write(error_unit,'(A)') 'JSON-Fortran Exception: '//trim(msg)
        error stop 1

    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)

        call tracebackqq(user_exit_code=-1)  ! print a traceback and return

        write(output_unit,'(A)') '***********************'

    end if

    end subroutine json_throw_exception