Sorry for the previous post, I answered too early. This code should be placed inside a try catch block, or better yet, inside the catch block. And if your method has a return type, make sure you're still returning something even after an exception
has been thrown.

This of course prevents you from throwing the exception if the posthandling action is set to any other than None. But this is I think is a better way of handling exception in web apps if you don't want to show the user what
is the exact exception that occured.