@@ -167,6 +167,11 @@ module json_value_module
167167
168168 logical (LK) :: is_verbose = .false. ! ! if true, all exceptions are
169169 ! ! 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+
170175 logical (LK) :: exception_thrown = .false. ! ! The error flag. Will be set to true
171176 ! ! when an error is thrown in the class.
172177 ! ! Many of the methods will check this
@@ -814,7 +819,8 @@ function initialize_json_core(verbose,compact_reals,&
814819 path_separator ,&
815820 compress_vectors ,&
816821 allow_duplicate_keys ,&
817- escape_solidus ) result(json_core_object)
822+ escape_solidus ,&
823+ stop_on_error ) result(json_core_object)
818824
819825 implicit none
820826
@@ -833,7 +839,8 @@ function initialize_json_core(verbose,compact_reals,&
833839 path_separator,&
834840 compress_vectors,&
835841 allow_duplicate_keys,&
836- escape_solidus)
842+ escape_solidus,&
843+ stop_on_error)
837844
838845 end function initialize_json_core
839846! *****************************************************************************************
@@ -869,7 +876,8 @@ subroutine json_initialize(me,verbose,compact_reals,&
869876 path_separator ,&
870877 compress_vectors ,&
871878 allow_duplicate_keys ,&
872- escape_solidus )
879+ escape_solidus ,&
880+ stop_on_error )
873881
874882 implicit none
875883
@@ -904,6 +912,8 @@ subroutine json_initialize(me,verbose,compact_reals,&
904912 ! various optional inputs:
905913 if (present (spaces_per_tab)) &
906914 me% spaces_per_tab = spaces_per_tab
915+ if (present (stop_on_error)) &
916+ me% stop_on_error = stop_on_error
907917 if (present (verbose)) &
908918 me% is_verbose = verbose
909919 if (present (strict_type_checking)) &
@@ -1789,6 +1799,8 @@ end subroutine json_clear_exceptions
17891799!
17901800! @note If `is_verbose` is true, this will also print a
17911801! traceback if the Intel compiler is used.
1802+ !
1803+ ! @note If `stop_on_error` is true, then the program is stopped.
17921804
17931805 subroutine json_throw_exception (json ,msg )
17941806
@@ -1804,14 +1816,31 @@ subroutine json_throw_exception(json,msg)
18041816 json% exception_thrown = .true.
18051817 json% err_message = trim (msg)
18061818
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 1
1827+ #endif
1828+
1829+ elseif (json% is_verbose) then
1830+
18081831 write (output_unit,' (A)' ) ' ***********************'
18091832 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+
18111838#ifdef __INTEL_COMPILER
18121839 call tracebackqq(user_exit_code=- 1 ) ! print a traceback and return
18131840#endif
1841+
18141842 write (output_unit,' (A)' ) ' ***********************'
1843+
18151844 end if
18161845
18171846 end subroutine json_throw_exception
0 commit comments