How to catch an error that isn't even caught by the OnException override?
So we have a base controller we are using and it contains an override for OnException that logs the error to our bug tracking tool. However I noticed that some errors never make it, and I'm wondering if it is somehow silly to expect an application to log all it's own errors when itself is the thing that is having an e开发者_如何学JAVArror, which could cause some errors never to be caught.. ? Either way what is the best solution, or should OnException always be expected to happen? Should I be putting some tool on Windows Server to log the errors instead of within the app itself?
I don't think I've ever seen an error that wasn't trappable at some point. I have application level logging also and like you i've implemented a base controller.
my base controller doesn't do any logging. instead i created a custom action filter with which i decorate my controllers and actions with and it does all the logging.
i also, in the global.asax, added code to the Application_Error event that does a bit of logging and also calls an error controller to handle the actual error.
I hope this in some way helps you. If you want any of the code i've mentioned then add a comment to this answer and i shall provide. it's not a lot of code either.
The Controller.OnException event can only catch events that are thrown in the scope of an executing Controller. There are events that happen before an http request is mapped to a controller and the OnException event will not capture these events. For example, if you have a controller factory that maps the RequestContext to a particular controller, than an exception thrown here is not in the scope of a Controller.
You should implement a "fail safe" exception handler in the global.asax.Application_Error event.
精彩评论