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.
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
Type | Intent | Optional | 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) |
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