@@ -167,6 +167,11 @@ module json_value_module
167
167
168
168
logical (LK) :: is_verbose = .false. ! ! if true, all exceptions are
169
169
! ! immediately printed to console.
170
+
171
+ logical (LK) :: stop_on_error = .false. ! ! if true, then the program is
172
+ ! ! stopped immediately when an
173
+ ! ! exception is raised.
174
+
170
175
logical (LK) :: exception_thrown = .false. ! ! The error flag. Will be set to true
171
176
! ! when an error is thrown in the class.
172
177
! ! Many of the methods will check this
@@ -814,7 +819,8 @@ function initialize_json_core(verbose,compact_reals,&
814
819
path_separator ,&
815
820
compress_vectors ,&
816
821
allow_duplicate_keys ,&
817
- escape_solidus ) result(json_core_object)
822
+ escape_solidus ,&
823
+ stop_on_error ) result(json_core_object)
818
824
819
825
implicit none
820
826
@@ -833,7 +839,8 @@ function initialize_json_core(verbose,compact_reals,&
833
839
path_separator,&
834
840
compress_vectors,&
835
841
allow_duplicate_keys,&
836
- escape_solidus)
842
+ escape_solidus,&
843
+ stop_on_error)
837
844
838
845
end function initialize_json_core
839
846
! *****************************************************************************************
@@ -869,7 +876,8 @@ subroutine json_initialize(me,verbose,compact_reals,&
869
876
path_separator ,&
870
877
compress_vectors ,&
871
878
allow_duplicate_keys ,&
872
- escape_solidus )
879
+ escape_solidus ,&
880
+ stop_on_error )
873
881
874
882
implicit none
875
883
@@ -904,6 +912,8 @@ subroutine json_initialize(me,verbose,compact_reals,&
904
912
! various optional inputs:
905
913
if (present (spaces_per_tab)) &
906
914
me% spaces_per_tab = spaces_per_tab
915
+ if (present (stop_on_error)) &
916
+ me% stop_on_error = stop_on_error
907
917
if (present (verbose)) &
908
918
me% is_verbose = verbose
909
919
if (present (strict_type_checking)) &
@@ -1789,6 +1799,8 @@ end subroutine json_clear_exceptions
1789
1799
!
1790
1800
! @note If `is_verbose` is true, this will also print a
1791
1801
! traceback if the Intel compiler is used.
1802
+ !
1803
+ ! @note If `stop_on_error` is true, then the program is stopped.
1792
1804
1793
1805
subroutine json_throw_exception (json ,msg )
1794
1806
@@ -1804,14 +1816,31 @@ subroutine json_throw_exception(json,msg)
1804
1816
json% exception_thrown = .true.
1805
1817
json% err_message = trim (msg)
1806
1818
1807
- if (json% is_verbose) then
1819
+ if (json% stop_on_error) then
1820
+
1821
+ #ifdef __INTEL_COMPILER
1822
+ ! for Intel, we raise a traceback and quit
1823
+ call tracebackqq(string= trim (msg), user_exit_code= 0 )
1824
+ #else
1825
+ write (error_unit,' (A)' ) ' JSON-Fortran Exception: ' // trim (msg)
1826
+ error stop ' JSON-Fortran Exception'
1827
+ #endif
1828
+
1829
+ elseif (json% is_verbose) then
1830
+
1808
1831
write (output_unit,' (A)' ) ' ***********************'
1809
1832
write (output_unit,' (A)' ) ' JSON-Fortran Exception: ' // trim (msg)
1810
- ! call backtrace() ! gfortran (use -fbacktrace -fall-intrinsics flags)
1833
+
1834
+ #if defined __GFORTRAN__
1835
+ ! call backtrace() ! (have to compile with -fbacktrace -fall-intrinsics flags)
1836
+ #endif
1837
+
1811
1838
#ifdef __INTEL_COMPILER
1812
1839
call tracebackqq(user_exit_code=- 1 ) ! print a traceback and return
1813
1840
#endif
1841
+
1814
1842
write (output_unit,' (A)' ) ' ***********************'
1843
+
1815
1844
end if
1816
1845
1817
1846
end subroutine json_throw_exception
0 commit comments