Exception (Exception)

Source: Internet
Author: User

Tag: null ERR Cannot find run programming error number throws exception no numbers

Abnormal

Exceptions that occur during Java operation can be divided into two categories:

1. Error: JVM system internal error, resource consumption and other serious situation

2. Exceptions (Exception): Other general issues caused by programming errors or accidental external factors

    1. You can throw exceptions in the method definition for the following scenarios

(1) A method that throws a "checked exception" is called in the method

(2) An error occurred while the program was running and a "checked exception" was thrown with the throw clause

A. Open square root to negative numbers

b. Null pointer access

C. Attempting to read a file that does not exist

D. Network connection interrupted

E. Denominator is 0

PS: Do not throw: those exceptions derived from the error

Java Exception handling mechanism

    1. When an exception occurs during the execution of a Java program, an exception class object is automatically generated, which is referred to the Java Runtime System, which is called throw (throw) exception----active
    2. When the Java runtime system receives an exception object, it looks for code that can handle the exception and hands the current exception object to its processing, a process known as catch (catch) exception----passive
    3. If the Java runtime system cannot find a way to catch an exception, the runtime system terminates and the corresponding Java program exits
    4. Programmers usually only deal with exception, and can do nothing about error errors

Common exceptions:

  1. RuntimeException
    1. ArithmeticException: Mathematical calculation anomalies
    2. NullPointerException: null pointer exception
    3. Negativearraysizeexception: Negative group length exception
    4. ArrayIndexOutOfBoundsException: Array index out-of-bounds exception
    5. ClassNotFoundException: Class file not found exception
    6. ClassCastException: Abnormal shape
  2. IOException
    1. FileNotFoundException: File not found exception
    2. Eofexception: Read-write file tail exception
    3. Malformedurlexception:url Format Error exception
    4. Socketexception:socket Exception (socket)
      1. Arithmetic Exception class: ArithmeticException
      2. Null pointer exception class: NullPointerException
      3. Type cast Exception: ClassCastException
      4. Array negative subscript exception: Negativearrayexception
      5. Array subscript out-of-bounds exception: ArrayIndexOutOfBoundsException
      6. Violation of security principle exception: Secturity Exception
      7. File ended exception: Eofexception
      8. File not found exception: FileNotFoundException
      9. string conversion to numeric exception: NumberFormatException
      10. Manipulating Database Exceptions: SQLException
      11. Input/Output exception: IOException
      12. Method not found exception: Notsuchmethodexception
      13. Abstract method Error Exception Java.lang.AbstractMethodError
      14. Assertion Error Exception Java.lang.AssertionError
      15. Class Loop dependency Error Exception Java.lang.ClassCircularityError
      16. PS: When an exception is not processed in the current try-catch, it will be thrown to the method that called it (throws)
      17. PS: When an exception has not been able to be processed and then returned to the main method, the program will stop running
      18. If the program requires information about the exception object to be accessed in the catch block, it can be obtained by calling the method of the exception parameter after the catch. When the Java runtime decides to call a catch block to handle the exception object, the exception object is assigned to the exception parameter after the catch block, and the program can obtain information about the exception by this parameter.

        GetMessage (): Returns the detailed description string for the exception

        Printstacktrace (): The error stack information for the exception is output on the screen

        Printstacktrace (PrintStream s): Outputs the trace stack information for this exception to the specified output stream

        Getstackreace (): Returns the trace stack information for this exception

Exception (Exception)

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.