I want to know if there is a good way to convert system generated errors into something more meaningful for the user. for example if for some reason the application could not connect to the SMTP server. I want to convert the message thrown by the system which will be something like "SMTP connection failure" to "We could not send you an email". This friendly message I want to pull out from a resource file. While this is an example of one such exception, there could be more.
We dont have try catch blocks across all the layers. It is present only in the UI layer. We have a exception management class that takes in all exceptions and returns a friendly string from it. Every catch block in the UI layer makes a call to this exception management class and passes it an exception of type System.Exception whose method needs to return the said friendly error string for use on the UI.
The only way I can think of doing this now is having one large IF ELSE block in the exception management class that checks the exception string received and pulls out a matching friendly message from the resource file.
Is there a better way to go about this?
That is why you have try catch to catch the exceptions. just use it with specific error types not the generic error type. so then you can display any message inside the catch block. but rethrowing the custom exception inside catch block is not recommended. In your case you can catch the System.Net.Mail.SmtpException
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With