Page 1 of 1

Throw in catch

Posted: Wed Oct 15, 2008 12:38 am
by pmliju
Hi all,

Is it good programming practice to catch one exception and re-throw it as some other exception type?

Thanks,
Liju Engandiyur

Re: Throw in catch

Posted: Wed Oct 15, 2008 2:43 am
by requinix
Not really. The only time I would do that is if I wanted to generalize the exception for something higher up in the chain. Otherwise just let it bubble up the call stack automatically (make sure you don't have a generic catch (Exception $e) then).

For example, the code inside catches a TodayIsNotAThursday exception and you rethrow a DateIsInvalid exception.