- class Chu {
- public int chu(int a, int b) throws FuShuExcepiton {
- if (b < 0)
- throw new FuShuExcepiton("哥们,你拿负数忽悠我呢!", b);
- return a / b;
- }
- }
- class ExceptionDemo {
- public static void main(String[] args) {
- try {
- new Chu().chu(3, -2);
- } catch (FuShuExcepiton e) {
- System.out.println(e.toString() + e.getVlae());
- }
- }
- }
- class FuShuExcepiton extends Exception {
- int vlae;
- FuShuExcepiton() {
- super();
- }
- FuShuExcepiton(String s, int vlae) {
- super(s);
- this.vlae = vlae;
- }
- public int getVlae() {
- return vlae;
- }
- }
复制代码
你那个代码里好多都是代码写错!!思路没错!!帮你改了一下 看看!!是不是你要的效果! |