Catching multiple exception types in one catch block

I’d like a cleaner way to obtain the following functionality, to catch AError and BError in one block:

try
{
    /* something */
}
catch( AError, BError $e )
{
    handler1( $e )
}
catch( Exception $e )
{
    handler2( $e )
}

Is there any way to do this? Or do I have to catch them separately?

AError and Berror have a shared base class, but they also share it with other types that I’d like to fall through to handler2, so I can’t just catch the base class.

12 Answers
12

Leave a Comment