本人在自定义异常抛出上,有一些问题,请各位不吝惜指教。先来看一则我写的小程序:- class DemoException extends Exception
- {
- DemoException()
- {
- super();
- }
- DemoException(String msg)
- {
- super(msg);
- }
- }
- class Plus
- {
- public int simplePlus(int a ,int b) throws DemoException
- {
- if(b==0 && a==0)
- throw new DemoException("the number u put is zero / by zero");
- return a+b;
- }
- }
- class Demo1
- {
- public static void main(String[] args)
- {
- Plus d=new Plus()
- try
- {
- System.out.println("the sum="+new plus().simplePlus(0,0));
- }
- catch (DemoException e)
- {
- System.out.println(e.toString());
- System.out.println("出错了。");
- }
- }
- }
复制代码 上面的自定义异常, throw new DemoException("the number u put is zero / by zero");
所抛出的新建异常实体,是否被
public int simplePlus(int a ,int b) throws DemoException
以 throws DemoException 将该在遇到问题时建立的实体抛出?在实际应用当中,是否还有其它的巧妙方法实?
|
|