Try-catch-finnal exception Handling in Java (Learning notes)

Source: Internet
Author: User

I. Overview of exceptions

Exception: Exception, is an abnormal condition that occurs during a run.

Raw Exception Handling:

if (condition) {Treatment Method 1
Treatment Method 2
Treatment Method 3
}
if (condition) {Treatment Method 4
Treatment Method 5
Treatment Method 6
}

Code reading poor, bloated, and the normal process code is very close, so, in Java a series of improvements, a series of common problems, using object-oriented thinking, the description, encapsulation.

Class handling method {    processing Method 1 ()    {    Example 1    }    handling Method 2 ()    {    Example 2}    }
if (Error)
{
throw new treatment 1 (); This method may contain the name of the problem, the information, the time, the location, and so on.
}

In Java, an abnormal condition is described and encapsulated in the form of a class. When there is a problem with the program, call the appropriate processing method.

A class that describes an unhealthy condition is called an exception class. Separates the process code from the exception code.

The exception is that Java encapsulates the problem as an object through object-oriented thinking. The exception class is used to describe it. Different problems, describe them in different classes. That means, how many problems there are, and how many classes there are.

second, abnormal system

Many problems, meaning that the description of the class is also a lot, the generality of the extraction, the formation of an anomaly system. The final exception is divided into two main categories :

Throwable (parent Class): The problem occurs, it should be thrown, let the caller handle it. The characteristic of this system is that both Throwable and its subclasses have parabolic properties.

Two keywords to achieve the parabolic: throws, throw

|--1. Generally non-processing. Error (Errors)

Feature: A problem with the severity thrown by the JVM (Java Virtual machine). This problem occurs, generally not targeted treatment, directly modify the program.

|--2. can be processed. Exception (Exception)

Features: The suffix of the subclass is the suffix of its parent class name, and the reading is very strong.

third, exception-principle & Throw Throw of exception object

Throw new Exception Method ();

Try-catch-finnal exception Handling in Java (Learning notes)

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.