0

I've been using Exception handling as a means to centralize my logging of errors into a database table for my application. I've used set_exception_handler() to route exceptions to a function which logs this information and continues after the error silently so as not to present the user with errors. This has been especially helpful in debugging because I can send messages to the db table simply by issuing:

throw new Exception("My message I want to check in the db table");

and check the db table to debug rather than the local log file. In essence - my goal is to replace the error_log() function capability alleviating the need to search to local webserver log files in a multi-server load-balanced situation.

It has been working great for me until I started writing Class files and doing the same thing - that is - using similar throw statements to pass information back. When I try to do this in a function within a class, the code execution does not continue past the throw statement back to the calling code where the class was instantiated. Code execution literally stops, silently, after logging the exception to the db table. I want the code to continue to execute after logging.

Is this some documented behavior in php that I'm not aware of? How can I change this or set up my class files so they behave like the rest of the application code?

Thanks in advance!

Ross
  • 1,639
  • 1
  • 18
  • 22
  • 2
    The code after a throw is not supposed to be run. After the exception is thrown, the function stops executing and execution of the appropriate `catch` block starts. If you want execution to continue you could consider using `trigger_error()` – user254875486 Nov 02 '12 at 10:55
  • Or try to throw the exception further using [throw](http://ch2.php.net/throw). – Louis Huppenbauer Nov 02 '12 at 10:56
  • Lex - thanks for the expected behavior after throw - that's what I was wondering. Also - trigger_error seems to be the better way to accomplish what I want. Below is another SO question which further helps. http://stackoverflow.com/questions/3992078/trigger-error-vs-throwing-exceptions – Ross Nov 06 '12 at 17:17

0 Answers0