Considerations for Java 19-11 Exceptions

Source: Internet
Author: User

1 /*2 * Exception precautions: 3 * A: When a subclass overrides a parent class method, the child class's method must throw the same exception or subclass of the parent exception. (father is broken, son can not be worse than father)4 * B: If the parent class throws more than one exception, when the subclass overrides the parent class, it can only throw the same exception or a subset of his, the subclass cannot throw exceptions that the parent class does not have5 * C: If the overridden method does not throw an exception, then the method of the subclass must not throw an exception, if there is an exception in the subclass method, then the subclass can only try, not throws6  */7 Importjava.text.ParseException;8 ImportJava.text.SimpleDateFormat;9 Importjava.util.Date;Ten  Public classExceptiondemo { One  A } -  - classFu { the      Public voidShow ()throwsException { -     } -  -      Public voidmethod () { +     } - } +  A classZiextendsFu { at @Override -      Public voidShow ()throwsArithmeticException { -  -     } -  - @Override in      Public voidmethod () { -         //String s = "2014-11-20"; to         //SimpleDateFormat sdf = new SimpleDateFormat (); +         //Date d = sdf.parse (s); -         //System.out.println (d); the     } *}

Considerations for Java 19-11 Exceptions

Related Article

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.