Logical function to indicate if an exception has been thrown in a json_core.
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
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(in) | :: | json |
will be true if an exception has been thrown.
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