Catch all exceptions .. Is it possible?

Hello folks!

Does anybody know if there is a way to catch all the exceptions in the controller? I’m developing a REST API and I would like to register in a table the input and output data. The input is easy, in the beforeAction method I can catch these information, however, for the output data I’ve tried to use the afterAction method, but, when an exception occurs this method isn’t even executed.


Custom error handler.