Only handle specific type of exception

Hi all,

What I’d like to do is handle the system error handler’s behaviour, but only for specific exception and error types.

For example: when a model can not be found, I throw a custom exception type (ModelNotFoundException). Now, this is an exception I want to handle - e.g. by setting the status code to 404.

I’ve accomplished this by setting a custom (class-based) errorHandler on the container, and this works fine. Here’s the catch though: I only want to handle a select few exception/error types, and for any other throwables I’d like to fallback to the default system error handler.

Any advice? Feel as if I’m missing something very obvious here…


  • E

Postscriptum: probably not relevant, but just in case: I’m using Slim with the PHP-DI bridge.

Here you can see an example

Thanks for the example: it did not solve my specific problem, but I have decided to take a different approach. Cheers!