Exception Handling : try block

In C++ what is the use of 'try' block? (when we are clearly 'throw'ing the issue) I think in Java, exception can be find at any place in the 'try' block.

otherwise 'try' is syntactical requirement to make 'throw' works?
otherwise 'try' is syntactical requirement to make 'throw' works?
The try/catch block is used to catch exceptions, not throw them.
closed account (E0p9LyTq)
C++ isn't Java, so forget how Java does exception handling when working with C++.

http://www.cplusplus.com/doc/tutorial/exceptions/
In C++ you don't need to mark that a function can throw exceptions. I guess you can think of them as unchecked exception in Java, like ArrayIndexOutOfBoundsException and NullPointerException, that does not require you to catch or mark the method as throwing.

On the contrary, in C++, if you know that a function can't throw exceptions you can mark it with noexcept if you want.
otherwise 'try' is syntactical requirement to make 'throw' works?
No. If there is no try for a throw the program will usually be exited.

I would think the naming is quite clear:

'catch' catches everything that is thrown within the 'try' block.

All c based language work this way.
@FurryGuy, You are true...
otherwise i am getting confuse :).
after leaving java concepts aside i am clear.
I don't know Java.
Less is more seems to be the guideline for exceptions.

The focus should be on catch, like coder777 says. Catch what? From where?
If this block X of code throws any of these exceptions Y, then I want to intercept and do Z.

By default we probably don't catch and handle anything from anywhere (at least on homework trivia). Therefore, the uncaught exceptions unwind the call stack all the way to main() and beyond. Looks like a crash of some sort.

What we might prefer is to choose operations that never throw. We then handle the error situations by other means than exceptions.
Topic archived. No new replies allowed.