@@ -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,25 +1911,27 @@ end subroutine wrap_json_throw_exception
1908
1911
!
1909
1912
! ### See also
1910
1913
! * [[json_failed]]
1914
+ ! * [[json_throw_exception]]
1911
1915
1912
- subroutine json_check_for_errors (json ,status_ok ,error_msg )
1916
+ pure subroutine json_check_for_errors (json ,status_ok ,error_msg )
1913
1917
1914
1918
implicit none
1915
1919
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)
1919
1925
1920
- status_ok = .not. json% exception_thrown
1926
+ if ( present (status_ok)) status_ok = .not. json% exception_thrown
1921
1927
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]
1924
1933
error_msg = json% err_message
1925
- else
1926
- error_msg = ' Unknown error.'
1927
1934
end if
1928
- else
1929
- error_msg = CK_' '
1930
1935
end if
1931
1936
1932
1937
end subroutine json_check_for_errors
@@ -8875,8 +8880,8 @@ subroutine annotate_invalid_json(json,iunit,str)
8875
8880
end if
8876
8881
8877
8882
! 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))// ' , ' // &
8880
8885
' character: ' // trim (adjustl (char_str))// newline// &
8881
8886
trim (line)// newline// arrow_str
8882
8887
0 commit comments