⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 excep.java

📁 Java 程序设计源码 只提供了部分
💻 JAVA
字号:

import java.io.*;

class Excep
{
        Excep()
        {
        }
        
        public int Division(int a,int b) throws ArithmeticException,DivisorIsMinusException//Exception
        {
                /*try
                {*/
                if(b < 0)
                        throw new DivisorIsMinusException("can't divide by minus");
                        return a/b; 
                /*}
                catch(ArithmeticException e)
                {
                        e.printStackTrace();
                        throw new Exception ("can't divide by zero");
                        //throw e;
                        //return 0;
                }*/
        }
        
        public int fn1(int a,int b) throws ArithmeticException,DivisorIsMinusException//Exception
        {
                return Division(a,b);
        }
}

class ChildExcep extends Excep
{
        ChildExcep()throws FileNotFoundException
        {
        }
        
        public int Division(int a,int b) throws ArithmeticException,DivisorIsMinusException
        {
                return a/b;
        }
}

class DivisorIsMinusException extends Exception
{
        DivisorIsMinusException(String str)
        {
                super(str);
        }
}

class main
{
        public static int Method1(Excep excep)
        {
                try
                {
                        return excep.Division(5,0);
                }
                catch(ArithmeticException e)
                {
                        //System.out.println("ArithmeticException");
                        System.out.println(e.toString());
                }
                catch(DivisorIsMinusException Excep)
                {
                        System.out.println(excep.toString());
                        System.exit(-1);
                        return 0;
                }
                catch(Exception e)
                {
                        //System.out.println("除数不能为零!");
                        e.printStackTrace();
                        //System.out.println(e.toString());
                }
                finally
                {
                        System.out.println("finally");
                }
                
                return 0;
        }
        public static void main(String[] args) //throws Exception
        {
                ChildExcep ce = new ChildExcep();
                
                Method1(ce);
                
                Excep ex = new Excep();
                
                try
                {                     
                        //e.division(5,0);   
                        ex.fn1(5,-1);
                        System.out.println("Exception");  
                        return;                   
                }
                catch(ArithmeticException e)
                {
                        //System.out.println("ArithmeticException");
                        System.out.println(e.toString());
                }
                catch(DivisorIsMinusException excep)
                {
                        System.out.println(excep.toString());
                        System.exit(-1);
                        return;
                }
                catch(Exception e)
                {
                        //System.out.println("除数不能为零!");
                        e.printStackTrace();
                        //System.out.println(e.toString());
                }
                finally
                {
                        System.out.println("finally");
                }
                
                System.out.println("finish");                           
        }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -