zoukankan      html  css  js  c++  java
  • 自定义异常

    package com.lsx.base;

    public class MyException extends Exception {
    private int detail;

    public MyException(int detail) {
    this.detail = detail;
    }

    @Override
    public String toString() {
    return "MyException{" +
    "detail=" + detail +
    '}';
    }
    }

    class TestDemo {
    public static void test(int a) throws MyException {
    System.out.println("传递的参数为:" + a);
    if (a > 10) {
    throw new MyException(a);
    }
    System.out.println("OK!");
    }

    public static void main(String[] args) {
    try {
    test(12);
    } catch (MyException e) {
    System.out.println("MyException==>" + e);
    }
    }
    }
  • 相关阅读:
    Demo
    Demo
    z-yelir-~
    CSP考前总结
    NOIP刷题
    清北学堂
    qsing
    【csp模拟赛九】--dfs3
    【csp模拟赛九】--dfs2
    【csp模拟赛九】--dfs
  • 原文地址:https://www.cnblogs.com/lsxsx/p/13356483.html
Copyright © 2011-2022 走看看