Abnormal operation
< p align = "center" > abnormal operation
< p class = "1" > I. fill in the blanks
2、 Multiple choice questions
Exception:1. It can be checked or unchecked;
2. Represents an error caused by a programmer;
3. Should be handled at the application level;
Error:1. Always unchecked;
2. It is often used to indicate system errors or underlying resource errors;
3. If possible, it should be captured at the system level;
Try is used to specify a program to prevent all "exceptions";
The catch clause immediately follows the try block to specify the type of "exception" you want to catch;
The throw statement is used to explicitly throw an "exception" (square);
Throws is used to indicate various "exceptions" that may be thrown by a member method (method declaration);
Finally, to ensure that a piece of code is executed no matter what "exception" occurs;
1: Location
Throws appears in the method header
Throw appears in the method body.
2: throw differences
Throws indicates a possibility of exceptions, which do not necessarily occur; Declared is an exception type
Throw throws an exception. Executing throw must throw an exception object.
3. Exception handling method
Both are negative exception handling methods (negative here does not mean that this method is bad), but only throw or possibly throw exceptions,
However, it will not be handled by the function. The real exception handling is handled by the upper call of the function.
1、 Coding question
Requirement: use custom exception implementation
2. Write a method void istriangle (int a, int b, int c) to judge whether the three parameters can form a triangle. If not, throw an exception illegalargumentexception and display the exception message "a, B, C can not form a triangle". If it can form, display the three sides of the triangle. Get the three integers entered on the command line in the main method and call this method, And catch exceptions.
5、 Topic selection