/**Author: Dai Meng Teacher*☑csdn Certified Lecturer*☑51cto Senior Lecturer*☑Tencent Classroom Certified Lecturer*☑NetEase Cloud Classroom Certified Lecturer*☑Huawei Developer School Certified Lecturer*☑iQiyi Thousand Talents Teacher Program Member* Here I will share with you all

2024/06/3014:08:32 technology 1102

/**Author: Dai Meng Teacher*☑csdn Certified Lecturer*☑51cto Senior Lecturer*☑ Tencent Classroom  Certified Lecturer*☑ NetEase Cloud Classroom  Certified Lecturer*☑Huawei Developer School Certified Lecturer*☑ iQiyi Members of the  Thousand Masters Program* are here to share with you technology, knowledge and life* and all kinds of useful information, remember to pay attention! *vx:it_daimeng*/

1. What is exception

Abnormality refers to abnormal status or behavior. This includes our human errors in operating the program, etc.

2. What is abnormal operation?

abnormal operation refers to the processing of these error operations.

3, why use exception

1, to avoid feedback errors that cannot be understood and cannot be processed.

2. During the running of the program, it does not affect the operation of other modules.

4. The purpose of learning exceptions is

to catch exceptions and throw exceptions.

5, Java exception mechanism

①throws statement

throws statement handles exceptions from the method/behavior level. Usually the exception we initialize is thrown in the entire method body.

public static void method( ) throws FileNotFoundException, ConnectionException { //code}

example

public class ExceptionBuilder {public static void main(String[] args) throws ClassNotFoundException {Class.forName("234");}}

②try-catch statement

Targeted exception handling, in short, is to handle specific exceptions. The characteristic of

is the independence of exception handling. At the same time, the time complexity and space complexity are improved in both directions.

try {Socket s = new Socket("127.0.0.1", 4555);} catch (IOException e) {e.printStackTrace();} 

try statements are placed in the statement block to be executed under normal expected conditions. It is mandatory in the try statement, and the statements in it will be mandatory checked. The

catch statement block is mainly used to handle checked exceptions and undetected exceptions thrown in the try statement block.

③finally statement

finally statement is the statement that is finally executed. It is a block of statements that must be executed regardless of whether the error affects the program.

try {Socket s = new Socket("127.0.0.1", 4555);} catch (IOException e) {e.printStackTrace();} finally {System.out.println("Continue");}

6, exception classification

/**Author: Dai Meng Teacher*☑csdn Certified Lecturer*☑51cto Senior Lecturer*☑Tencent Classroom Certified Lecturer*☑NetEase Cloud Classroom Certified Lecturer*☑Huawei Developer School Certified Lecturer*☑iQiyi Thousand Talents Teacher Program Member* Here I will share with you all - DayDayNews

technology Category Latest News