Exception handling mechanism in Java throw throws custom business logic exception throws continues to throw catch capture and will automatically continue to throw the calling method

Source: Internet
Author: User
Tags try catch

 PackageCom.swift; Public classEXCEPTION_TESTC { Public Static voidMain (string[] args) {/** Question 5th: There is a class ClassA, there is a class of CLASSB, there is a method B in ClassB, this method throws an exception, in the ClassA class there is a * method A, call B in this method, and then throw an exception. In a client that has a class of TESTC, there is a method for C, please catch the exception information in this method. Java Exception Handling mechanism * * If there is a return in a try or catch, execute a try catch finally return,catch to see if there is an exception in the try-throw is an exception thrown Throws is a declaration exception, throw is used in the method body, used to throw an actual exception object, after using throw, either using the try * Catch catch exception, or using throws declaration exception catch can throw an exception again in order to call its methods to catch again and processing * Custom exceptions are used to mark exceptions for business logic and avoid confusion with standard exceptions*/        NewTESTC (). c (); }}classA { Public voidA ()throwsException {Newb (). b (); }}classB { Public voidB () {Try {            intA =-1; if(A < 0) {                Throw NewMyException ("B ..... You cannot use negative numbers. Throw by Classb.methodb "); }        } Catch(MyException e) {e.printstacktrace (); }    }}classtestc{ Public voidC () {Try {            NewA (). a (); } Catch(Exception e) {e.printstacktrace (); }    }}classMyExceptionextendsException { Publicmyexception (String msg) {Super(msg); }}

Exception handling mechanism in Java throw throws custom business logic exception throws continues to throw catch capture and will automatically continue to throw the calling method

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.