Skip to content

Choosing Exceptions to Raise

Jeff Tratner edited this page Jun 16, 2013 · 2 revisions

Choosing Exceptions to Raise

This is an opinionated (start) to a guide to using Exceptions in Pandas.

Overall: use builtin exceptions wherever possible and avoid using raise Exception!

Builtin Exceptions

Again, looking at the docs on builtin exceptions is the best way to decide which to use (even includes explanations of what each sort of Exception is meant for).

Using Pandas-provided Exception

There are a number of exceptions sprinkled throughout...maybe we'll get to documenting all of them.

Using PandasError

Try to limit PandasError usage to cases where it really is something specific to Pandas (like this error from pandas/core/format.py):

    # validate mi options
    if self.has_mi_columns:
        if cols is not None:
            raise PandasError("cannot specify cols with a multi_index on the columns")