0

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?

itaka
  • 399
  • 1
  • 5
  • 16
  • If you would have spent a few minutes trying, maybe you could have found the answer to your question. – Simon Forsberg Nov 07 '12 at 14:20
  • really I'm not working with an easy code, I'm new in the company and this is the code they have :S, is legacy, procedural, full of bad practices, not clean and very bad I think.........is not a good code.I dont know how to manage it for now. – itaka Nov 07 '12 at 14:33

2 Answers2

3

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.

Keith
  • 54
  • 3
2

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,

didierc
  • 14,572
  • 3
  • 32
  • 52