package com.soar.exception;
public class Demo6_Exception {
/*
* A: Throws to handle abnormalities
* When defining the function method, the problems that appear need to be exposed for the calling person to deal with it.
* Then the method is identified by Throws.
* B: Case demonstration
* For example, the abnormal and abnormal throwing during the compilation of the compilation
* The abnormality of compilation must be processed by it
* The abnormalities at the run can be processed or not handled
*************************************************** ************
* A: Throw Overview
* Some cases appear inside the function method. The program cannot continue to run. When jumping is needed, use Throw to throw an abnormal object.
* B: Case demonstration
* Demonstrate the abnormal object and the abnormal object during the compilation of the compilation
* C: Throws and Throw
* A: Throws
* Use behind the method to declare, follow the abnormal category name
* You can separate it with multiple abnormal categories and use comma
* It means throwing an exception, and the caller of this method is handled
* B: Throw
* Used in the method body, follow the abnormal object name
* You can only throw out an abnormal object name
* Indicates throwing abnormality, and the statement in the method is processed
*/
public static void main(String[] args) throws Exception {
Person p = new Person();
p.setAge(-17);
System.out.println(p.getAge());
}
}
class Person{
private String name;
private int age;
public Person() {
super();
}
public Person(String name, int age) {
super();
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) throws Exception,RuntimeException {
if(age > 0 && age <=150){
this.age = age;
}else{
// Exception E = New Exception ("Age illegal");
//throw e;
throw new Exception("Age illegal"); // Writing above
}
}
}
SAP-Abap Learning Record (2)
2023-02-01