I want to handle exceptions thrown by any controller action with an ErrorView model and an error view. The idea was to have something like:
[InformClientOfExceptions(typeof(MyErrorHandler))]
public ActionResult MyAction(Int32 someId)
{
//...code
}
Then maybe have some class MyErrorHandler which implements a new interface IErrorView:
public class MyErrorHander : IErrorView
{
public ActionResult OnException(Exception ex)
{
//..code which converts exception to some error view model and returns the view
When an exception is thrown by the action, the attribute cooks up the class specified and passes the exception to it, the exception is then handled (in the basic case formatted and output). Now yes, exceptions should never occur, or at least be properly handled, but I would like a better way of writing this. I don't want to use a custom error page as I would like to extend this pattern to allow for more complex responses to certain types of exception. Any ideas how best to approach this?