D
D
Dmitry2016-05-04 00:08:13
ASP.NET
Dmitry, 2016-05-04 00:08:13

How to properly handle Exception?

Hello! Tell me how to properly handle the Exception? The application is divided into 3 layers: DAL, BLL, Presentation, for example, in one of the data samples in the DAL layer, an Exception fell out, what should I do with it next?
1) Do I need to drag it to the Presentation layer?
2) Do I need to write to the log?
3) Do I need to display an error to the user?
4) What to do with the method in which the Exception jumped out, if this method returns something, is it necessary to return null?
Please tell me effective methods for handling such situations, I sketched out the questions that first came to mind, because I have not encountered such a problem before

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
VanKrock, 2016-05-04
@VanKrock

This question is very strange, it all depends on you, if you want to show the user an error, then you show it, if you don’t want to, then don’t show it. The same is with the logs, if you need a record of this error, then you write it to the log, if you do not need it, then do not write it down. You need to understand how the user will work with your application, what he will do in case of errors, who he will contact for example, who will deal with this error, and what information this person will need in order to identify and fix the problem.
Just think about what and who will need it. If a user creates an application, and an exception has been thrown on your request, does he need to show that an error occurred during registration? Probably necessary. Does he need detailed connection information and the entire stack trace? Probably not. Does your application's support team need detailed information? Maybe yes. Does the support service need a stack trace if they don't have access to the access code? Probably not much. But the developer will not interfere with the stack trace.
So look at your business process for resolving issues with your application.

R
Roman, 2016-05-05
@yarosroman

No, the user only needs to show the page, like, something went wrong, save the log, and send an error notification to the developers (mail, etc.). Displaying exception messages is useful only during development, in production, the error detail is even fraught with hacking. It is better to screw up validation, and display validation errors, that's right.

#
#algooptimize #bottize, 2016-05-09
@user004

Really thrown exceptions affect performance, keep in mind if it is critical.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question