A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

本帖最后由 青苹果 于 2014-5-31 17:16 编辑

class Chu
{
public int chu(int a,int b)throws FuShuException
{
  if (b<0)
   throw new FuShuException("哥们,你拿负数忽悠我呢!"+b);
  return a/b;
}
}

class ExceptionDemo
{
public static void main(String[] args)
{

try
{
  new Chu().chu(3,-1);
}
catch (FuShuException e)
{
  System.out.println(e.toString()+e.getVial());
}
}
}



class FuShu extends Exception
{

    int vlae ;
     FuShu()
     {         super();             }

     FuShu(String s ,vlae)
     {   
         super(s);
         this.vlae =vlae;
               
     }
    public int  getVlae()
     {
     return vlae;

     }
}

e.getVial();  返回的负数中为毛后面还要跟着一个零呢   

返回结果是 -10

7 个回复

正序浏览
  1. class Chu {
  2.         public int chu(int a, int b) throws FuShuExcepiton {
  3.                 if (b < 0)
  4.                         throw new FuShuExcepiton("哥们,你拿负数忽悠我呢!", b);
  5.                 return a / b;
  6.         }
  7. }

  8. class ExceptionDemo {
  9.         public static void main(String[] args) {

  10.                 try {
  11.                         new Chu().chu(3, -2);
  12.                 } catch (FuShuExcepiton e) {
  13.                         System.out.println(e.toString() + e.getVlae());
  14.                 }
  15.         }
  16. }

  17. class FuShuExcepiton extends Exception {

  18.         int vlae;

  19.         FuShuExcepiton() {
  20.                 super();
  21.         }

  22.         FuShuExcepiton(String s, int vlae) {
  23.                 super(s);
  24.                 this.vlae = vlae;

  25.         }

  26.         public int getVlae() {
  27.                 return vlae;

  28.         }
  29. }
复制代码

你那个代码里好多都是代码写错!!思路没错!!帮你改了一下 看看!!是不是你要的效果!
回复 使用道具 举报
饥渴ing 发表于 2014-5-31 17:19
看不出来问题...你还是重新整理下题目吧

已经重新整理好了
回复 使用道具 举报
青苹果 发表于 2014-5-31 16:19
class FuShu extends Exception
{

看不出来问题...你还是重新整理下题目吧
回复 使用道具 举报
More 发表于 2014-5-31 17:02
你首先要写给FuShuException类去继承Exception吧

写了的 文字忘了复制上去  写在2楼在  
回复 使用道具 举报
你首先要写给FuShuException类去继承Exception吧
回复 使用道具 举报
class FuShu extends Exception
{

    int vlae ;
     FuShu()
     {         super();             }

     FuShu(String s ,vlae)
     {   
         super(s);
         this.vlae =vlae;
               
     }
    public int  getVlae()
     {
     return vlae;

     }


}
回复 使用道具 举报
FuShuException这个类呢。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马