views:

64

answers:

1

Since HandleError is inherited by the derived Controllers, why wouldn't I just create (or have) a base controller, and apply HandleError on it so that any controllers that inherits from the base controller will automatically be handled as well?

And then I would tack on overriding HandleError on controllers and individual actions.

Can anyone think of any reason why I wouldn't want to apply HandleError to the base controller?

A: 

To me HandleError on a base controller is like surrounding your entire application with a try{} catch{} block. You've essentially stopped treating exceptions like exceptions made them a normal occurrence in your application.

You could only "catch" what you know may happen and not everything that may happen.

jfar
HandleError is pretty generic in itself unless you derive from it to create a custom HandleError attribute. All it really does is redirect the browser to an error page. It is in this context, that I ask the original question. It is not to actually "handle" any particular exception as much as it is to handle an unhandled exception. For example, I use ELMAH to log unhandled exceptions but I want to use HandleError. So I created a derived HandleError to log to ELMAH in addition to default redirection that takes place. This is very generic and is not controller specific as you can see.
Jiho Han
Well to me redirecting a user to an error page is handling the error in some way. Is this a "prove me wrong" question?
jfar
not sure what you mean by "prove me wrong" question... but yes, redirecting to an error page is handling the error but it's generic and it applies to all controllers so why wouldn't I put a single HandleError on the base controller and be done with it?
Jiho Han