why (if at all) is a bad idea?
class Program { static void Main(string[] args) { try { throw new NotImplementedException("Oh dear"); } catch (Exception ex) { throw NewException("Whoops", ex); } }
The important thing here is that the function throws an exception of the same type as the "innerException".
I think ... "Oh ... an exception occurred. I can't handle it here, but I can add more information and throw it. Maybe another handler, above the call, the chain can handle it."
An example would be some SQL error. I may not be able to handle the exception at the time of the call, but I may wish to add additional “contextual” information, for example, “I called this and passed it.”
It seems that it would be useful to pass a backup of the call chain to an exception from the type that was originally created, as opposed to “Exceptions” or “Application Exceptions”. I know that I can create my own exception classes, but it seems like it doesn't add anything when you already have a wonderful specific exception.
Of course, I could be wrong. It can be very useful to do ... but a small voice does not offer.
----- edit -----
For discussion purposes, consider the effects of the following two functions (using the code above):
This ... is too often seen:
static int SalesTotal(int customerNumber) { try { throw new DivideByZeroException();
against it...
static int SalesTotal(int customerNumber) { try { throw new DivideByZeroException();
c # exception-handling
Black light
source share