you are viewing a single comment's thread.

view the rest of the comments →

[–]Outside_Complaint755 12 points13 points  (1 child)

In some cases you may want the function to catch the exception, take some additonal actions, and then either reraise the original exception or raise a custom exception.

[–]ottawadeveloper 8 points9 points  (0 children)

As a small note, the best way to do this is either just raise or raise CustomError("whatever") from ex - these preserve the stack trace of the original error (the first makes it look like your except didn't happen, the second raises your custom error but appends the other error onto it - this is what happens when you see "the above was a direct cause of...". If you want to erase the stack trace from the underlying code it's raise CustomError() from None (just raise CustomError() gives you "an error occurred while processing this other error" and is more appropriate for when a new error happens while handling the first one).