Skip to content

Wrap pyo3_runtime.PanicException in your own custom exception #445

Open
@ondrej-ivanko

Description

@ondrej-ivanko

Hi,

would it be possible to wrap the pyo3_runtime.PanicException raised by Python ffi bindings in pyo3 to your own custom exception which would inherit from Exception class and be exportable to third party code?

I'm running the code in Celery task and they're somewhat allergic to System exceptions caused by unhandled Rust code.
For mode details see this post

So far, I'm forced to use this solution:

try:
    # run some whitebox functionality
except BaseException as exc:
    # solution to avoid installing `pyo3` dependency
    if exc.__class__.__name__ == "PanicException":
        raise WbPanicException(
            "Whitebox function failed with unexpected exception"
        ) from exc

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions