Exception
Posted fatrabbit-
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Exception相关的知识,希望对你有一定的参考价值。
- 自定义异常
/** * 自定义异常类 */ public class TestException extends Exception { private String message; public TestException(String message) { this.message = message; } @Override public String getMessage() { return this.message; } }
/**
* 验证用户信息
*/
@Override
public boolean verify() throws TestException {
String err_msg = "";
isOk = false;
//验证用户名、密码、手机、邮箱是否为空或者空字符串
if (getUsername() == null || getUsername().equals(""))
err_msg = "用户名不能为空";
else if (getPassword() == null || getPassword().equals(""))
err_msg = "密码不能为空";
else if (getPhone() == null || getPhone().equals(""))
err_msg = "手机不能为空";
else if (getEmail() == null || getEmail().equals(""))
err_msg = "邮箱不能为空";
//判断异常字符是否为空
if (!err_msg.equals("")) {
isOk = false;
throw new TestException(err_msg);
}
return isOk;
}//获取输出流对象
PrintWriter out = resp.getWriter();
boolean isOk = false;
try {
isOk = uc.getResult();
if (isOk) {
UserContextService usc = new UserContextService(1);
usc.getResult(ub);
if (usc.isOk() == true) {
out.println("注册成功");
}
} else {
out.println("注册失败");
}
} catch (TestException e) {
out.println(e.getMessage());
}
以上是关于Exception的主要内容,如果未能解决你的问题,请参考以下文章
使用java.lang.Exception的错误:测试类应该只有一个公共构造函数
Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library 'dll