I am using Enterprise Library's DAAB to access a database, both with ExecuteReader
and ExecuteNonQuery
. The problem is that these methods do not have exceptions thrown documented... How can I, then, know which exceptions should I catch?

- 3,244
- 8
- 27
- 48
-
I'm just curious why you think you need to catch every possible exception? The specific exceptions thrown will depend on your database provider since most errors will probably be database or networking (connectivity etc.) exceptions. Also, most of the exceptions are going to be system exceptions where I don't think you can do much besides logging and probably letting the user know that there was an error. – Randy Levy Jun 29 '11 at 15:42
2 Answers
I agree with WebTurner, I'm guessing a good place to start would be which database your connecting to, so if an ms sql database I'm guessing a couple of (perhaps many) exceptions would be:
- SqlException
- InvalidOperationException
http://msdn.microsoft.com/en-us/library/9kcbe65k.aspx
EDIT:
I just came across this: How can I determine which exceptions can be thrown by a given method?
Which looks liek it uses reflection to help uncover a list of exceptions that are thrown.

- 1
- 1

- 16,657
- 11
- 74
- 152
-
Effectively what you've done is found out which exceptions would be returned by one lower level operation and server type. It's not a bad start but you'd need to examine the whole implementation in EL to find the exceptions raised. – Stephen Turner Jun 29 '11 at 12:53
-
Totally agree @webturner, thanks for the added detail. This just gives a start, but certainly not thorough. – Alex KeySmith Jun 29 '11 at 12:59
The problem is that there are many exceptions that will be thrown at a lower level than the enterprise library, and it would be impossible for EL to document all of these.
I suggest you use the exception handling and logging blocks to catch and log all exceptions. You can then see which ones occur and adapt the configuration of the exception handler or add new code to handle the specific execptions.

- 7,125
- 4
- 51
- 68
-
The problem is that I am already catching and handling a lot of different exceptions "manually"... Will I be able to adapt them to the new handling block? – User Jun 29 '11 at 12:17
-
Yes, although when I switched from manual exception handling and finally got a grasp of Enterprise library I found I massivley reduced the amount of exception handling code that was required, and also had much better coverage of exceptions raised in code. – Stephen Turner Jun 29 '11 at 12:24