@@ -227,6 +227,11 @@ class CliRunner:
227227 to `<stdout>`. This is useful for showing examples in
228228 some circumstances. Note that regular prompts
229229 will automatically echo the input.
230+ :param catch_exceptions: Whether to catch any exceptions other than
231+ ``SystemExit`` when running :meth:`~CliRunner.invoke`.
232+
233+ .. versionchanged:: 8.2
234+ Added the ``catch_exceptions`` parameter.
230235
231236 .. versionchanged:: 8.2
232237 ``mix_stderr`` parameter has been removed.
@@ -237,10 +242,12 @@ def __init__(
237242 charset : str = "utf-8" ,
238243 env : cabc .Mapping [str , str | None ] | None = None ,
239244 echo_stdin : bool = False ,
245+ catch_exceptions : bool = True ,
240246 ) -> None :
241247 self .charset = charset
242248 self .env : cabc .Mapping [str , str | None ] = env or {}
243249 self .echo_stdin = echo_stdin
250+ self .catch_exceptions = catch_exceptions
244251
245252 def get_default_prog_name (self , cli : Command ) -> str :
246253 """Given a command object it will return the default program name
@@ -410,7 +417,7 @@ def invoke(
410417 args : str | cabc .Sequence [str ] | None = None ,
411418 input : str | bytes | t .IO [t .Any ] | None = None ,
412419 env : cabc .Mapping [str , str | None ] | None = None ,
413- catch_exceptions : bool = True ,
420+ catch_exceptions : bool | None = None ,
414421 color : bool = False ,
415422 ** extra : t .Any ,
416423 ) -> Result :
@@ -429,7 +436,8 @@ def invoke(
429436 :param input: the input data for `sys.stdin`.
430437 :param env: the environment overrides.
431438 :param catch_exceptions: Whether to catch any other exceptions than
432- ``SystemExit``.
439+ ``SystemExit``. If :data:`None`, the value
440+ from :class:`CliRunner` is used.
433441 :param extra: the keyword arguments to pass to :meth:`main`.
434442 :param color: whether the output should contain color codes. The
435443 application can still override this explicitly.
@@ -457,6 +465,9 @@ def invoke(
457465 traceback if available.
458466 """
459467 exc_info = None
468+ if catch_exceptions is None :
469+ catch_exceptions = self .catch_exceptions
470+
460471 with self .isolation (input = input , env = env , color = color ) as outstreams :
461472 return_value = None
462473 exception : BaseException | None = None
0 commit comments