itaka
itaka

Reputation: 399

bubling up the exceptions in PHP?

Supposing I have this scenario:

function1() call to function2(), and function2() call to function3().

if function3() throws an exception, can I capture the exception from function1()?

And in the case in which maybe, some of these functions is in a different class?, can I continue capturing from function1?

Upvotes: 0

Views: 56

Answers (2)

didierc
didierc

Reputation: 14730

That's the whole point of exceptions. You can capture them at any point in the function (whether it be a simple function, or a method call) call stack using a try catch statement,

Upvotes: 2

Keith
Keith

Reputation: 54

If you don't catch the exception then it will automatically bubble up through the call stack. If you've not caught the exception in function2 or function3, you'll be able to catch it in function1.

Upvotes: 3

Related Questions