devide是怎么定义的,能发上来看看吗

解决方案 »

  1.   

    你的DevideByMinusException可能写的不对,我猜是没有继承ArithmeticException 
    你看我下面写你是不是你想得到的/*
     * Created on 2005-2-12
     *
     * TODO To change the template for this generated file go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
    package com.ess.test;/**
     * @author zhang
     *
     * TODO To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Style - Code Templates
     */
    public class DevideByMinusException extends ArithmeticException { /**
     * @return
     */
    public String getDevisor() {
     
    return null;
    }}package com.ess.test;public class TestException {
    public static void main(String[] args) {
    try {
    int result =  devide(3, 0);
    // int result = new Test().devide( 3, -1 );
    // int result = new Test().devide( 3, 1 );
    System.out.println("the result is " + result);
    } catch (DevideByMinusException e) { 
    System.out.println("the devisor is " + e.getDevisor());
    }  
    System.out.println("program is running here ,that is normal !");
    } /**
     * @param i
     * @param j
     * @return
     */
    private static int devide(int i, int j) {
     if(j==0)
      throw new DevideByMinusException();
    return i/j;
    }
    }
      

  2.   

    /*
        @(#) DivideByMinusException.java
     */package com.quickpoint;
    /**
          DivideByMinusException  is a self defined exception class.  
     */
    public class DivideByMinusException extends Exception
    {
        /**
               exception msg String;
         */
        private String msg;
        /**
               Constructor
         */
        public DivideByMinusException(String msg)
        {
                this.msg = msg;
         }
        /**
               Override toString method
               @return string representation of the exception
         */
        public String toString()
         {
               return msg;
         }
        /**
              your divider code here...
         */    public String getDivider()
        {
                  // ...
        }
    }
      

  3.   

    回star_str(生命火花):  这是张孝祥<<Java就业培训教程>>P154页的内容, 全在这里了.
      

  4.   

    catch(DevideByMinusException e)  这里自定义异常的名称写错了吧应该是
    catch(DivideByMinusException e)