zoukankan      html  css  js  c++  java
  • 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 = "";

      //验证用户名、密码、手机、邮箱是否为空或者空字符串
      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());
      }
       
  • 相关阅读:
    mysq foreign外键记录
    查询时隐藏部分身份证号
    SpringBoot接收前端参数
    RabbbitMQ安装
    @configurationProperties注解时 idea弹出 Spring Boot Annotion processor not found in classpath
    rpm,yum和apt使用详解
    python人脸识别
    Fuchsia文章汇总
    Androi O Automotive 介绍
    Linux 版本控制工具之rabbitvcs
  • 原文地址:https://www.cnblogs.com/fatRabbit-/p/10163719.html
Copyright © 2011-2022 走看看