@@ -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,6 +1911,7 @@ end subroutine wrap_json_throw_exception
19081911!
19091912! ### See also
19101913! * [[json_failed]]
1914+ ! * [[json_throw_exception]]
19111915
19121916 pure subroutine json_check_for_errors (json ,status_ok ,error_msg )
19131917
@@ -1923,11 +1927,10 @@ pure subroutine json_check_for_errors(json,status_ok,error_msg)
19231927
19241928 if (present (error_msg)) then
19251929 if (json% exception_thrown) then
1926- if (allocated (json% err_message)) then
1927- error_msg = json% err_message
1928- else
1929- error_msg = ' Unknown error.' ! this should never happen
1930- end if
1930+ ! if an exception has been thrown,
1931+ ! then this will always be allocated
1932+ ! [see json_throw_exception]
1933+ error_msg = json% err_message
19311934 end if
19321935 end if
19331936
@@ -8877,8 +8880,8 @@ subroutine annotate_invalid_json(json,iunit,str)
88778880 end if
88788881
88798882 ! create the error message:
8880- json% err_message = json% err_message// newline// &
8881- ' 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))// ' , ' // &
88828885 ' character: ' // trim (adjustl (char_str))// newline// &
88838886 trim (line)// newline// arrow_str
88848887
0 commit comments