4

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!

4

1 回答 1

6

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:

  1. 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.

  2. The script execution halts after your handler is done.

于 2012-11-14T01:58:18.170 回答