@@ -176,7 +176,10 @@ module json_value_module
176
176
! ! when an error is thrown in the class.
177
177
! ! Many of the methods will check this
178
178
! ! 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.
180
183
181
184
integer (IK) :: char_count = 0 ! ! character position in the current line
182
185
integer (IK) :: line_count = 1 ! ! lines read counter
@@ -1804,7 +1807,7 @@ pure subroutine json_clear_exceptions(json)
1804
1807
1805
1808
! clear the flag and message:
1806
1809
json% exception_thrown = .false.
1807
- json% err_message = CK_ ' '
1810
+ if ( allocated ( json% err_message)) deallocate (json % err_message)
1808
1811
1809
1812
end subroutine json_clear_exceptions
1810
1813
! *****************************************************************************************
@@ -1908,6 +1911,7 @@ end subroutine wrap_json_throw_exception
1908
1911
!
1909
1912
! ### See also
1910
1913
! * [[json_failed]]
1914
+ ! * [[json_throw_exception]]
1911
1915
1912
1916
pure subroutine json_check_for_errors (json ,status_ok ,error_msg )
1913
1917
@@ -1923,11 +1927,10 @@ pure subroutine json_check_for_errors(json,status_ok,error_msg)
1923
1927
1924
1928
if (present (error_msg)) then
1925
1929
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
1931
1934
end if
1932
1935
end if
1933
1936
@@ -8877,8 +8880,8 @@ subroutine annotate_invalid_json(json,iunit,str)
8877
8880
end if
8878
8881
8879
8882
! 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))// ' , ' // &
8882
8885
' character: ' // trim (adjustl (char_str))// newline// &
8883
8886
trim (line)// newline// arrow_str
8884
8887
0 commit comments