Library Exception Handling Policy

When creating a .NET library, what is the exception handling policy? In particular, what is your policy for handling exceptions within the library that raises and exposes them to invoke code?

For instance,

  • Would you consider a library function like any other, thus allowing all the exceptions that it cannot handle to follow from it as it is?
  • Would you create a custom exception for this library?
  • Will you catch all exceptions and instead throw a library exception? Would you set the original exception as the internal exception of the library exception?
  • How does database dependency on a library affect your exception handling policy?

What recommendations and rules would you suggest for handling exceptions in the .NET library?

+5
source share
3 answers

Will you consider the library function like any other, thereby allowing all exceptions, it can not cope with the flow from it as-is?

Yes, this is definitely the default strategy.

Would you create a custom exception for this library?

Yes, if callers can possibly do something with the situation and , in order to do this, they must be able to distinguish an exception from other exceptions. But this is quite rare.

How does database dependency on a library affect your exception handling policy?

, , (, MaximumDeadlockRetries).

? ? ?

, . , , , , - ( ) .

+1
  • , , , . , , (IO ..).
  • , . O/R "DataAccessException", SQL - . , , SQL, ( , ..) - .
  • .
  • ( addomain - ), .

- . , .

+2

, , , . , , .

, MagicDatabaseLibrary MagicDatabaseException, , , MagicDatabaseTimeoutException, MagicDatabaseAuthenticationException .. SQL Server - SQL Server ( , ), MagicDatabaseTimeoutException. , .

, , , , " Pokemon", - . , , , , . , , , , , , - , , , , .

0

All Articles