Print any error message, and then clear the exceptions.
Note
This routine is used by the unit tests. It was originally in json_example.f90, and was moved here 2/26/2015 by Izaak Beekman.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(json_core), | intent(inout) | :: | json | |||
integer, | intent(in), | optional | :: | io_unit |
unit number for printing error message |
subroutine json_print_error_message(json,io_unit) implicit none class(json_core),intent(inout) :: json integer, intent(in), optional :: io_unit !! unit number for !! printing error message character(kind=CK,len=:),allocatable :: error_msg !! error message logical :: status_ok !! false if there were any errors thrown integer(IK) :: istat !! for write error checking character(kind=CK,len=max_integer_str_len) :: tmp !! for int to string conversions !get error message: call json%check_for_errors(status_ok, error_msg) !print it if there is one: if (.not. status_ok) then if (present(io_unit)) then write(io_unit,'(A)',iostat=istat) error_msg if (istat/=0) then ! in this case, just try to write to the error_unit call integer_to_string(io_unit,int_fmt,tmp) write(error_unit,'(A)',iostat=istat) 'Error writing to unit '//trim(tmp) write(error_unit,'(A)',iostat=istat) error_msg end if else write(output_unit,'(A)',iostat=istat) error_msg end if deallocate(error_msg) call json%clear_exceptions() end if end subroutine json_print_error_message