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(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

Type Bound

json_core

Arguments

Type IntentOptional Attributes Name
class(json_core), intent(in) :: json
logical(kind=LK), intent(out), optional :: status_ok

true if there were no errors

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

the error message. (not allocated if there were no errors)


Called by

proc~~json_check_for_errors~~CalledByGraph proc~json_check_for_errors json_core%json_check_for_errors proc~json_file_check_for_errors json_file%json_file_check_for_errors proc~json_file_check_for_errors->proc~json_check_for_errors proc~json_print_error_message json_core%json_print_error_message proc~json_print_error_message->proc~json_check_for_errors proc~json_value_validate json_core%json_value_validate proc~json_value_validate->proc~json_check_for_errors proc~json_file_print_error_message json_file%json_file_print_error_message proc~json_file_print_error_message->proc~json_print_error_message

Source Code

    subroutine json_check_for_errors(json,status_ok,error_msg)

    implicit none

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

#if defined __GFORTRAN__
    character(kind=CK,len=:),allocatable :: tmp  !! workaround for gfortran bugs
#endif

    if (present(status_ok)) status_ok = .not. json%exception_thrown

    if (present(error_msg)) then
        if (json%exception_thrown) then
            ! if an exception has been thrown,
            ! then this will always be allocated
            ! [see json_throw_exception]
#if defined __GFORTRAN__
            tmp = json%err_message
            error_msg = tmp
#else
            error_msg = json%err_message
#endif
        end if
    end if

    end subroutine json_check_for_errors