Puoi utilizzare queste funzioni

set_error_handler
set_exception_handler