The basic idea of exception handlingThe basic idea of the exception handling of C + + can be summarized as the traditional error handling mechanism and the function return value to handle the error.
1 The exception handling mechanism of C + +
Throw throws/passes an exception by using the throw statement in the Catch Block. exceptions that can be changed. For example, we can throw a new exception. Throw statements have various types and are necessary.
ExampleFirst, let's take a look at
For Java programmers, NULL is a headache. is often harassed by null-pointer anomalies (NPE). Even the inventor of Java admits it was a huge mistake. Why should Java keep null? Null has been around for some time, and I think the Java inventor knows
Throw new exception (string, exception)
Throw new exception (string)
Throw explicitly throws an exception.
Msdn: exception (string, exception) initializes a new instance of the exception class by specifying the error message and referencing
Hi, everybody good evening, my blog first beginning, let's cheer together!All say the Java language is very robust, such as: garbage collection mechanism, memory model, exception handling, strong type conversion, cross-platform, and so on, so that
Online Comparison of classic summary:Any function can fail, and the constructor is not otherwise, such as the new object or the space is unsuccessful. When the constructor fails, there are many times when we don't want the object to be generated,
Whether it is. NET or Java, in the development process will inevitably use the Throw keyword, for beginners will generally think it and try...catch bundled together, this is certainly wrong, in fact, throw one of the most important role is:
Let the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.