Using Exception class in C #

Errors that occur deep in the data access layer or even higher (for example, as part of ADO.net operations) rarely make sense to the end user. Simply using these errors before the user interface and displaying them usually does not achieve anything but disappointment for the end user.

I recently used a basic method for reporting errors such as this, as a result of which I caught the error and at least added some convenient text so that at least the end user understood that it was not possible.

To do this, I caught an exception in each specific function (for example, a sampling function at the data access level), and then raising a new error with convenient text about a function that failed and probably caused, but then nesting the original exception to the new exception as the “internal exception” of this new exception.

Then this can happen on each layer, if necessary, each consumer of the lower-level function adds its own context to the error message, so that what reaches the user interface becomes more and more user-friendly error message.

Once the error reaches the user interface - if necessary - it can iterate through the nested exceptions to display an error message that first tells the user which operation failed, but also provides a little technical information about what is actually gone wrong.

eg.

"The list of your customer names cannot be displayed."

"Getting the list of customers you requested an error due to an error with the database."

"A database error occurred while retrieving a list of clients"

"Login failed for user xx"

, ( )? , , - - ?

+5
6

.

, . " , ". , " ?". "- ". , - , - (, application_error) . - , - .

, .

, . , , ( , " sql-: * , username = 'a'; drp database;." : "drop" "drp". , ).

+9

, , "" - 100 , , , ; 1000 , (, - - ).

, , . , , , , , :

  • -, ?
  • -, , ?
  • , , ?

, , . , - , .

, , () . , , ( ) , ? , , , , , , .

, Framework , . , ( " " ). , , , - . , , ( ). , . "" , , try/catch , "log and throw" .

, : , . ( "", , ), , - - .

, , (.. "" ). - , , , , , , . - , .

:

http://www.codeproject.com/KB/architecture/exceptionbestpractices.aspx

http://aspalliance.com/1119

, ... .

+8

, , , .

! , , , . , ? . ? - "". - .

, , .

+3

, . , , , , .

+2

, , . , ...

  • - - , , , , ( ).

  • , ( ).

  • , excpetion, , , .

, , " ". anbd , , , . (, ).

  1. . , , , .
+2

, , - . , - , . , , , , , .

+1

All Articles