json_failed Function

private pure function json_failed(json) result(failed)

Logical function to indicate if an exception has been thrown in a json_core.

Example

    type(json_core) :: json
    type(json_value),pointer :: p
    logical :: status_ok
    character(len=:),allocatable :: error_msg
    call json%load(filename='myfile.json',p)
    if (json%failed()) then
        call json%check_for_errors(status_ok, error_msg)
        write(*,*) 'Error: '//error_msg
        call json%clear_exceptions()
        call json%destroy(p)
    end if

Note that json_file contains a wrapper for this routine, which is used like:

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

See also

Arguments

Type IntentOptional AttributesName
class(json_core), intent(in) :: json

Return Value logical(kind=LK)

will be true if an exception has been thrown.


Contents

Source Code


Source Code

    pure function json_failed(json) result(failed)

    implicit none

    class(json_core),intent(in) :: json
    logical(LK)                 :: failed  !! will be true if an exception
                                           !! has been thrown.

    failed = json%exception_thrown

    end function json_failed