A
apa
There are a few well-known (?) guidelines to throwing/creating exceptions
(paraphrasing my understanding of it):
1. Don't throw general types like Exception or ApplicationException.
2. Use existing exception classes where it makes sense (ArgumentException
etc).
3. Don't create custom exception types if they don't add anything of value.
(Value can be just being able to catch that exception and nothing else.)
However, where I get confused is where I don't have any specific information
to add about an exception, and don't expect any special exception handling
to occur. For example, say I do a database query, which very unexpectedly
returns an empty result set. I basically just want to
throw new Exception("no data from db");
FxCop will have issues with that though. Should I create a
"MyApplicationException" for the none-of-the-above stuff? It seems to break
rule #3.
Thanks!
(paraphrasing my understanding of it):
1. Don't throw general types like Exception or ApplicationException.
2. Use existing exception classes where it makes sense (ArgumentException
etc).
3. Don't create custom exception types if they don't add anything of value.
(Value can be just being able to catch that exception and nothing else.)
However, where I get confused is where I don't have any specific information
to add about an exception, and don't expect any special exception handling
to occur. For example, say I do a database query, which very unexpectedly
returns an empty result set. I basically just want to
throw new Exception("no data from db");
FxCop will have issues with that though. Should I create a
"MyApplicationException" for the none-of-the-above stuff? It seems to break
rule #3.
Thanks!