There is one situation that you can do something about. If you are
having to distinguish between two exceptions coming out of one of your
own routines, but which originate in two different calls down to the
..NET Framework, you can catch each of them in your code and "wrap" them
in different exceptions so that you can distinguish them.
For example, if you have a method:
public void DoSomethingOrOther(object param1, object param2)
{
// Call a Framework method with param1
FrameworkMethod1(param1);
// Call a Framework method with param2
FrameworkMethod2(param2);
}
Now, either of these calls could throw an ArgumentNullException, if one
of param1 or param2 was null. Which framework method throws the
exception depends upon which argument is null. From the outside of
DoSomethingOrOther, the two exceptions are indistinguishable. However,
you could change that by doing this:
public void DoSomethingOrOther(object param1, object param2)
{
try
{
// Call a Framework method with param1
FrameworkMethod1(param1);
}
catch (ArgumentNullException ane)
{
throw new MyApplicationException("Something-or-other can't be
null.", ane);
}
// Call a Framework method with param2
FrameworkMethod2(param2);
}
Now you can distinguish the (recoverable) condition of the first
parameter being null from the (unrecoverable) condition of the second
parameter being null.
Of course, this works only in this circumstance. It doesn't work if a
single Framework method happens to throw the same exception under two
different conditions, and you want to recover from one and not the
other. In that case, you're out of luck.
