@@ -176,7 +176,10 @@ module json_value_module
176176 ! ! when an error is thrown in the class.
177177 ! ! Many of the methods will check this
178178 ! ! and return immediately if it is true.
179- character (kind= CK,len= :),allocatable :: err_message ! ! the error message
179+ character (kind= CK,len= :),allocatable :: err_message
180+ ! ! the error message.
181+ ! ! if `exception_thrown=False` then
182+ ! ! this variable is not allocated.
180183
181184 integer (IK) :: char_count = 0 ! ! character position in the current line
182185 integer (IK) :: line_count = 1 ! ! lines read counter
@@ -1804,7 +1807,7 @@ pure subroutine json_clear_exceptions(json)
18041807
18051808 ! clear the flag and message:
18061809 json% exception_thrown = .false.
1807- json% err_message = CK_ ' '
1810+ if ( allocated ( json% err_message)) deallocate (json % err_message)
18081811
18091812 end subroutine json_clear_exceptions
18101813! *****************************************************************************************
@@ -1908,25 +1911,27 @@ end subroutine wrap_json_throw_exception
19081911!
19091912! ### See also
19101913! * [[json_failed]]
1914+ ! * [[json_throw_exception]]
19111915
1912- subroutine json_check_for_errors (json ,status_ok ,error_msg )
1916+ pure subroutine json_check_for_errors (json ,status_ok ,error_msg )
19131917
19141918 implicit none
19151919
1916- class(json_core),intent (inout ) :: json
1917- logical (LK),intent (out ) :: status_ok ! ! true if there were no errors
1918- character (kind= CK,len= :),allocatable ,intent (out ) :: error_msg ! ! the error message (if there were errors)
1920+ class(json_core),intent (in ) :: json
1921+ logical (LK),intent (out ),optional :: status_ok ! ! true if there were no errors
1922+ character (kind= CK,len= :),allocatable ,intent (out ),optional :: error_msg ! ! the error message.
1923+ ! ! (not allocated if
1924+ ! ! there were no errors)
19191925
1920- status_ok = .not. json% exception_thrown
1926+ if ( present (status_ok)) status_ok = .not. json% exception_thrown
19211927
1922- if (.not. status_ok) then
1923- if (allocated (json% err_message)) then
1928+ if (present (error_msg)) then
1929+ if (json% exception_thrown) then
1930+ ! if an exception has been thrown,
1931+ ! then this will always be allocated
1932+ ! [see json_throw_exception]
19241933 error_msg = json% err_message
1925- else
1926- error_msg = ' Unknown error.'
19271934 end if
1928- else
1929- error_msg = CK_' '
19301935 end if
19311936
19321937 end subroutine json_check_for_errors
@@ -8875,8 +8880,8 @@ subroutine annotate_invalid_json(json,iunit,str)
88758880 end if
88768881
88778882 ! create the error message:
8878- json% err_message = json% err_message// newline// &
8879- ' line: ' // trim (adjustl (line_str))// ' , ' // &
8883+ if ( allocated ( json% err_message)) json % err_message = json% err_message// newline
8884+ json % err_message = ' line: ' // trim (adjustl (line_str))// ' , ' // &
88808885 ' character: ' // trim (adjustl (char_str))// newline// &
88818886 trim (line)// newline// arrow_str
88828887
0 commit comments