Inherited exceptions and inspections
Hello!
I have a problem with subject. Often for complicated modules I make a base exception and bunch of exceptions that inherits a base exception like on this screenshot http://prntscr.com/iyu0md
And use it like this http://prntscr.com/iyu127
But it cause a problem with inspections: "Unhandled BaseException" and "Exception '{exception_name}' is never thrown in corresponding try block", http://prntscr.com/iyu2sv
Is anyone know how to deal with it?
Please sign in to leave a comment.
Hi there,
AFAIK you should use actual thrown exceptions instead of generic parent:
Right now IDE is correct: you have declared that method throws BaseException .. but trying to handle child exceptions .. which, accordingly to the PHPDoc, will never be thrown. FooException is instance of BaseException but NOT other way around.
It's the same as declare that method throws just Exception .. and then check for specific InvalidArgumentException...
Sad... It cause a big problem when you have a couple of dozens of exceptions that can be thrown in method...