Click here to Skip to main content
15,887,376 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have override OnException Method in my MVC BaseController.
protected override void OnException(ExceptionContext filterContext)

Do we need to handle exception in this method? What will happen if some error occurred in this method?
What is the best practice to handle this scenario.

Regards,
Saurabh

What I have tried:

I tried to look at different approach like using try catch inside OnException but nothing seems correct to me till now.
Posted
Updated 13-Feb-20 5:32am
v2
Comments
jimmson 13-Feb-20 8:10am    
You seem to misunderstand what "protected" means in this case. Question would be much more clear if you can include your code.
saurabh.15in 13-Feb-20 9:05am    
Thanks Jimmson for reply.
I am not referring to protected access specifier.
My doubt is, what we can do if some exception occurred in OnException Method itsself. I have implemented my own logging here.
Example : Some error occurred in Application-> It comes to OnException and try to log the exception in DB using some logger-> some exception occurred in logger itsself(lets say DB connection is lost) again there will be exception inside Onexception. Now what we can do to handle this situation.

1 solution

You normally keep your exception handling code simple and very robust so it can't throw its own exceptions. That means not taking anything for granted. If you're doing database work, you NEVER assume the connection works and the table you're writing to exists.

On top of that, you also have to think about logging your errors in an alternate place, guaranteed to work if the database fails.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900