First of all, most people solve this error without catching the exception. Thus, the exception applies to ASP.NET, which displays the "500 Internal Error" web page and all relevant information is logged.
If your server is set up for production, the error page will simply say: "an error has occurred, details have been registered."
If the server is configured for development, you will get the famous yellow page with the exception type, message and stack trace.
Swallowing the exception and manually redirecting to the error page is bad practice because it hides errors. There are tools that study your logs and give you good statistics, such as percentages of successful / unsuccessful requests, and they will no longer work.
So, not swallowing an exception is what people do, and at least it solves your problem.
Now I find this very awkward because I donβt like to manually search for the source files mentioned on the yellow page and manually jump to the specified line numbers. I practically do not use the yellow page, it can simply say: "An error has occurred, cry to me with the river, damn it." I do not read the yellow page.
Instead, I like to write exceptions myself, and I have a logger starting each line with full-path-to-source-filename(line): so that each line in the debug log in visual studio is clickable and clicking on the line automatically the right source file opens and scrolls to the exact line that issued the log message. If you want this luxury, then go ahead and catch the exception, but immediately after registering the exception, you must rebuild it so that everything can follow their normal course.
Amendment
Here is some info added in the comments:
So you can do the following:
try { ... } catch (Exception e) { log( "information" ); throw;
or
try { ... } catch (Exception e) { throw new Exception( "information", e );
Do not do this: catch( Exception e ) { log( "information" ); throw e; } catch( Exception e ) { log( "information" ); throw e; } catch( Exception e ) { log( "information" ); throw e; } because it loses the original trace information of stack e .
Mike nakis
source share