LMSouq
general-dev Open

Catching multiple exception types in one catch block

DO
Dominic Gurto
1 month ago
3 views
Problem Description
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.

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base