Hi
I know it is not good to just put a try catch with Exception on it since that could lead to burying problems and other things.
I however still don't know if I should do it in my case.
My site is heavy ajax so I send json responses back. So right now I have identified some possible exceptions that could be raised like a null reference, sql db and etc.
So in the catch statement of these ones I would have a nice message to the user something like
a database error has occurred your stuff has not been saved
However I am thinking what happens if their is some other exception that I don't see right now. If that would happen I think the form would just hang and the user would not know what is going on.
So would it be better in this case to
- catch exceptions that I identified -such as sql, outof range
- log with elmah
- show nice customized msg for each exception
- catch Exceptions after
- log with elmah
- show some generic msg
- come back and add that exception list.
So
catch(IndexOutOfRangeException ex)
{
// log here
// customized msg
}
catch(Exception ex)
{
// log here
// generic msg
// come back and add another exception later on what actually failed.
}
instead of
catch(IndexOutOfRangeException ex)
{
// log here
// customized msg
}