set_exception_handler for specific exceptions

Viewed 60

I'm using a new API and I want to handle exceptions specific to it, and return the data from the exceptions to JS function that made a request. The thing is - I have a fatal_handler registered with register_shutdown_function in the program, and I want to avoid it for these exceptions, because It won't let me return the necessary data to the JS function, and I don't want to mess with this specific handler because it's more general. I managed to override it with set_exception_handler, but I assume it will catch other unhandled exceptions as well.

Is there any way to define the instance of the exception (e.g AException) that will be handled in set_exception_handler(), same as in a catch block?

My only idea was to check the type of the exception object I'm getting to the handler function (with instanceof, and rethrow it if it's not the type I'm looking for.

0 Answers
Related