Skip to content

Allow creating an Exception hierarchy #3452

@stinodego

Description

@stinodego

I'd like to be able to create an exception hierarchy in PyO3. In Python I would write something like:

class PolarsError(Exception):
    ...

class OutOfBoundsError(PolarsError):
    ...

Then users could catch the specific error thrown by the code (OutOfBoundsError), or use catch more general exception type (PolarsError).

Right now, I'm using the create_exception! macro to define the exceptions, as mentioned in the user guide. However, this does not allow for specifying a hierarchy.

I've found some discussion on subclassing exceptions:

...from this, it seems like my wish is already possible. However, I cannot find any code examples of how this is supposed to work. If it is already possible, could someone point me in the right direction? If not, consider this a feature request!

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