J2SE basics: 11. Exception Handling, j2se Exception Handling

Source: Internet
Author: User

J2SE basics: 11. Exception Handling, j2se Exception Handling

1: Concept of exceptions:


An exception is an event that occurs when the program is executed (an exception occurs during running ).

The program encountered an error and interrupted the original execution process.


2: Exception Handling in Java.



In Java, exceptions are encapsulated into an object. (Attributes and methods)


3: Exceptions


During Java program execution, if an exception event occurs, an exception object is generated.
The generated exception object is passed to the Java runtime system. The exception generation and submission process is called
To cause an exception.


4: exception Classification


Throwable)
Error: Error (an Error that cannot be processed by the Program)

Exception: Exception (an error that can be handled. The program can capture and handle these exception events)


5: Exception classification:


RunTimeException (exception during Operation)

Non-RunTimeException (exceptions during compilation)




6: RunTimeException exception


RunTimeException exceptions can be caught or not handled in the program.


7: Non-RunTimeException


Non-RunTimeException exceptions must be captured; otherwise, the program cannot
Normal compilation.



8: how to handle exceptions:


When an exception occurs, if the exception is not handled, the exception is directly thrown to the virtual machine.
Prepare the machine for processing. If the virtual machine cannot be processed, the program exits directly.


A: capture and handle exceptions


Try {
} Catch (){
}
Exception parameter object:
The object has been instantiated. You can directly call the method in the object.
Print exception stack information: e. printStackTrace ();
Print exception information: e. getMessage ();


Finally:
Whether it is a try block or a catch Block, the finally block will be executed after the execution is complete.
.

The resource object that is opened is disabled.

Finally, final, finalize

B: throws an exception and asks the next object to handle the exception.


Throw: throws an exception manually.

Throws: declares an exception. If you declare this method, an exception occurs. The exception must be handled.


Note:

A: A try can be followed by multiple catch ();

B: When a catch exception occurs, a small exception must be caught before a large exception is caught.

The same is true for throws.

C: When an exception is caught, the exception must be handled.

D: Do not put all the code into the try block and try to execute it. (Try block should be executed in the memory)

What are J2SE basics?

1 Java Introduction 2 basic syntax 3 object-oriented 4 exception handling 5 arrays 6 common Class 7 container 8io stream 9 thread 10 network 11GUI
 
What is java basic?

The name has been changed. It is called java se. It can be called java se as long as the website and mobile phone are not involved.

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.