Object-oriented (exception Overview), object-oriented (Overview)

Source: Internet
Author: User

Object-oriented (exception Overview), object-oriented (Overview)

   

/**
* Created by rabbit on 2014-08-05.
* Exception: the program is abnormal during running.
* Exception occurs. The problem is also a specific thing in real life.
* It is described in the form of java classes and encapsulated into objects. Actually
* Java describes the object after the exception.
*
* One type of problem is serious, and the other is non-serious.
*
* For serious cases, java uses the Error class to describe
* Generally, no specific code is written to handle errors.
*
* For non-serious cases, java uses the Exception class to describe
* You can use targeted methods to handle exceptions.
*
* Both Error and Exception have some common content.
* For example, abnormal information and causes
*
* Throwable
* | -- Error
* | -- Exception
*/
Class Demo3
{
Int div (int a, int B)
{
Return a/B;
}
}
Public class ExceptionDemo {
Public static void main (String [] args)
{
Demo3 d = new Demo3 ();
Int x = d. div (4, 0 );
System. out. println ("x" + x );
System. out. println ("over ");
}
}

   


/*
* Running result
*
* Exception in thread "main" java. lang. ArithmeticException:/by zero
At Demo3.div (ExceptionDemo. java: 8)
At ExceptionDemo. main (ExceptionDemo. java: 15)
At sun. reflect. NativeMethodAccessorImpl. invoke0 (Native Method)
At sun. reflect. NativeMethodAccessorImpl. invoke (NativeMethodAccessorImpl. java: 57)
At sun. reflect. DelegatingMethodAccessorImpl. invoke (DelegatingMethodAccessorImpl. java: 43)
At java. lang. reflect. Method. invoke (Method. java: 601)
At com.intellij.rt.exe cution. application. AppMain. main (AppMain. java: 134)
*
**/


Which of the following statements about object concepts in Object-Oriented Programming is false ()

3
The class should be the encapsulation body of the state and operation.

Who can explain how to handle exceptions in java object-oriented code?

Try {

} Catch (Exception e ){

} Finally {

}

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.