091108 t throw exception

Source: Internet
Author: User

For writeProgramA small problem for people with high speed is as follows:
(Original method)
Void method (Object Arg ){
String name = Arg. tostring ();
}

(New method)
Void method (Object Arg ){
If (ARG = NULL) throw new argumentnullexception ();
String name = Arg. tostring ();
}

Here we should execute the display judgment on the parameter Arg and throw an exception.
Although the original method will throw an exception when Arg is null, there are two failures:
1. The thrown exception is not the specified argumentnullexception, but the default nullreferenceexception.
2. (important) if the exception is self-controlled, it should be thrown explicitly! The reason is Readability: when someone else reads this program, they will not think that the author has not considered this problem.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.