Difference between exception handling in C++ and Java?

前端 未结 5 1799
孤城傲影
孤城傲影 2021-02-04 00:45

In Java, if a specific line of code causes the program to crash, then the exception is caught and the program continues to execute.

However, in C++, if I have a piece of

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-04 01:32

    1. C++ and Java both have try and catch blocks but Java have one new block finally which always executed after try and catch.
    2. Java throw only objects but C++ throws data(primitive and pointer & objects).
    3. C++ have catch(...) { } to catch all exception of all kinds and Java have catch(Exception e) { } to catch all exception .

提交回复
热议问题