question

VaruniRao-5484 avatar image
0 Votes"
VaruniRao-5484 asked TimonYang-MSFT edited

Handling exceptions multiple ways in asp.net application

In my application I need to display error message in two different ways based on severity.
1. Contacting Administrator if severity is high.
2. User handling the error by themselves without contacting administrator.

I achieved first one like as follows:
Try
{
//code
}
catch(Exception ex)
{
Exception("Contact Admin");
}

How to achieve 2nd one can anyone five solutions for this.

Thanks In Advance.



dotnet-csharpdotnet-aspnet-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DuaneArnold-0443 avatar image
0 Votes"
DuaneArnold-0443 answered DuaneArnold-0443 edited

@VaruniRao-5484


A user with a browser cannot handle an exceptions his or herself.

There should be using global exception handling in the solution with the exception.message, stack trace and inner.exception if inner.excpetion is not null being logged to a log file with a redirect to a user friendly error page about "contact site administration". You can review what has been logged to the log file. Log4Net is a good logging framework you can use.

You don't need any try/catch in any code, becuase the global exception handler code catches all exceptions even for code that has been referenced by the project that is doing the referencing to the referenced project or DLL.

https://stackify.com/csharp-catch-all-exceptions/

Q&A has tags for dotnet.ASP.NET you can post to for help.

HTH

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.