Reputation: 259
I wanted to convert notices into exceptions. I put the whole website inside of the try-catch block - each error (in try block) will call the set_error_handler() method which will throw new ErrorException. Then the exception is being caught, and the proper message is being displayed.
What SHOULD happen next is - everything after the E_NOTICE inside of the try block should be executed. When the next error occurs, everything happens again the same way, until the try block is over.
However, the try block seems to break after an exception is being caught.
How to handle this?
Upvotes: 0
Views: 42
Reputation: 494
At the point where an exception is thrown, execution stops in the try
block. If there is a catch that matches the exception (or all exceptions), that block is run. At that point, the program continues after the catch (which, if it is the end of the program, causes it to exit). It can't pick up where it left off inside the try section.
Throwing an exception is unrecoverable, up until the point it is caught (if it is). If you want to recover from it, you have to catch it at the point before the one at which you want code to resume. So you just need more than one try/catch, not one for the whole site. Or don't throw an exception on each E_NOTICE. Can I ask why you want notices to generate exceptions in the first place? There might be a better way to accomplish what you're trying to do with that.
Upvotes: 2