Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
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) |
Retrieve error code from the module. This should be called after json_parse to check for errors. If an error is thrown, before using the module 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
subroutine json_check_for_errors(status_ok, error_msg)
implicit none
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. exception_thrown
if (.not. status_ok) then
if (allocated(err_message)) then
error_msg = err_message
else
error_msg = 'Error: json_initialize() must be called first to initialize the module.'
end if
else
error_msg = ''
end if
end subroutine json_check_for_errors