Throw in catch

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pmliju
Forum Newbie
Posts: 2
Joined: Mon May 15, 2006 4:17 am

Throw in catch

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Throw in catch

Post 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.
Post Reply