json_check_for_errors Subroutine

private subroutine json_check_for_errors(json, status_ok, error_msg)

Retrieve error code from the json_core. This should be called after parse to check for errors. If an error is thrown, before using the class again, json_initialize should be called to clean up before it is used again.

Example

     type(json_file) :: json
     logical :: status_ok
     character(kind=CK,len=:),allocatable :: error_msg
     call json%load_file(filename='myfile.json')
     call json%check_for_errors(status_ok, error_msg)
     if (.not. status_ok) then
         write(*,*) 'Error: '//error_msg
         call json%clear_exceptions()
         call json%destroy()
     end if

See also

Arguments

Type IntentOptional AttributesName
class(json_core), intent(inout) :: json
logical(kind=LK), intent(out) :: status_ok

true if there were no errors

character(kind=CK,len=:), intent(out), allocatable:: error_msg

the error message (if there were errors)


Contents

Source Code


Source Code

    subroutine json_check_for_errors(json,status_ok,error_msg)

    implicit none

    class(json_core),intent(inout) :: json
    logical(LK),intent(out) :: status_ok !! true if there were no errors
    character(kind=CK,len=:),allocatable,intent(out) :: error_msg !! the error message (if there were errors)

    status_ok = .not. json%exception_thrown

    if (.not. status_ok) then
        if (allocated(json%err_message)) then
            error_msg = json%err_message
        else
            error_msg = 'Unknown error.'
        end if
    else
        error_msg = CK_''
    end if

    end subroutine json_check_for_errors