How to actually capture PanicException? #5704
-
|
So, I've read a lot of issues about try:
complicated_python_and_rust_library(strIn)
except (Exception, PanicException) as e:
with push_scope() as scope:
scope.add_attachment(
bytes=strIn.encode(),
)
capture_exception(e)
raise ePanicException is not a thing in python. I can't import it from my extension either. I've seen just catch BaseException, and re-throw it if it's not Panic, but how do you do that and also catch like... other logic Exceptoins except BaseException as e:
if not "PanicException" in str(type(e)):
raiseBut, all regular exceptions will not be Panic... except (Exception, BaseException) as e:
if not "PanicException" in str(type(e)):
raise e
with push_scope() as scope:
scope.add_attachment(
bytes=strIn.encode(),
)
capture_exception(e)
raise eI'm just looking for one example of how to work with Panic/Base exception in its current form. I'm trying to log asserts and unwrap Nones. Thanks Edit: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
|
Why do you want to handle |
Beta Was this translation helpful? Give feedback.
-
|
I think something like this will allow me to capture my library exceptions from python, and None::unrwrap() from the Rust code w/o accidentally dealing with new exceptions that I really don't want to mishandle try:
complicated_python_and_rust_library(strIn)
except (Exception, BaseException) as e:
if str(type(e)) in ["BaseExceptionGroup", "GeneratorExit", "KeyboardInterrupt", "SystemExit"]:
raise e
with push_scope() as scope:
scope.add_attachment(
bytes=strIn.encode(),
)
capture_exception(e)
raise e |
Beta Was this translation helpful? Give feedback.
I think you can write it like this:
I didn't include handling for
BaseExceptionGroupbecause I haven't needed to work with exception groups at all yet, so don't really know what to suggest there. But https://docs.python.org/3/tutorial/errors.html#raising-and-handling-multiple-unrelated-exceptions is probably a good resource.