用java创建一个异常类,将其命名为MyException,继承自Exception类。
发布网友
发布时间:2022-05-06 13:48
我来回答
共2个回答
热心网友
时间:2023-10-09 20:43
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class MyException extends Exception {
private String content;
MyException(String content) {
this.content = content;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
public class Example {
public void check(String str) {
String pattern = "^[A-Za-z]+$";
Pattern pa = Pattern.compile(pattern);
Matcher matcher = pa.matcher(str);
if (!matcher.matches()) {
throw new MyException("字符串包含字母以为的字符");
}
}
}
热心网友
时间:2023-10-09 20:44
您这是要别人给代码吗?