Reputation: 8697
I started using "real" Exceptions instead of custom error-functions.
I think I don't need a try/catch-block everytime and its okay just to throw an exception but now I get an fatal error because of these uncaught exceptions.
Everything works fine when I set error_reporting(0) but I want to avoid errors at all. Does anyone know an alternative to try/catch or how to throw an exception without getting an fatal error?
Thanks in advance!
Upvotes: 4
Views: 1072
Reputation: 173532
You can use set_exception_handler()
for that and handle any uncaught exceptions yourself.
The callback that you register will receive the exception as its first and only argument. Registering a dummy function is possible, however:
In a production environment it's recommended to log the exception instead of muffling it; this way you can keep track of exceptions that you didn't expect.
The script execution halts after your handler is done.
Upvotes: 6