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
The point of exceptions, in any language, is, or should be, to handle exceptional cases. But still cases where you can make reasonable assumptions about the global program state, and possibly recover. Programming errors generally mean that you can make no assumptions about the global program state, and must terminate the code as quickly as possible, executing the least additional code (since you don't know what it will do).
In Java, practically everything is reported by means of an exception. Everything from common, expected errors ("file not found" when trying to open a file) to critical internal errors (java.lang.VirtualMachineError). C++ gives you the choice: if you detect a coding error (assertion failure), you can abort the process immediately (generally more appropriate than stubling on in an unknown state); if the "error" is something which will normally occur in everyday operation ("file not found"), you can test the status, or use a return code (again, usually more appropriate than an exception). For a number of situations between the two (e.g. out of memory), C++ uses exceptions.
What is most appropriate in a given application, of course, varies:
there are certainly cases where "file not found" is exceptional (e.g. if
the file is part of the application, which can't run without it), and
warrants an exception. Similarly, in specific cases, a null pointer can
be used to control program logic (if ( ptr == NULL ) ...
) or
correspond to an exceptional case (if ( ptr == NULL ) throw ...
); in
other cases, a null pointer is a programming error
(assert( ptr != NULL)
).