How do I handle exceptions thrown in controller constructors in ASP.NET MVC?

Question

Grade: Education Subject: Support
How do I handle exceptions thrown in controller constructors in ASP.NET MVC?
Asked by:
76 Viewed 76 Answers

Answer (76)

Best Answer
(483)
Exceptions thrown in controller constructors are more challenging to handle with `HandleError` directly. You typically need to implement global exception handling in `Application_Error` within `Global.asax`. Within `Application_Error`, check if the exception originates from a controller constructor. If so, you can redirect to a specific error view or perform other appropriate actions. Dependency Injection can also help manage constructor dependencies and potential exceptions.