lesson44.java

来自「一些JavaAPI测试的源代码(包括一些Java中常用的数据结构类」· Java 代码 · 共 75 行

JAVA
75
字号
class Test
{
	public int devide(int x,int y) throws ArithmeticException,DevideByMinusException
	{
		if(y<0)
		{
			throw new DevideByMinusException("devisor is "+y);
		}
		int result = x/y;
		return result;
	}
	
	/*
	void fun()
	{
		try
		{
			if(x==0)
			{
				throw new XxxException("xxx");
			}
			else
			{
				throw new YyyException("Yyy");
			}
		}
		catch(XxxException e)
		{
			/...	
		}
		catch(YyyException e)
		{
			/...
		}
	}
	*/
}

class DevideByMinusException extends Exception
{
	public DevideByMinusException(String msg)
	{
		super(msg);
	}
}

class TestException
{
	public static void main(String[] args) throws Exception
	{
		try
		{
			return ;
			new Test().devide(3,0);
		}
		catch(ArithmeticException e)
		{
			//e.printStackTrace();
			System.out.println("b");
		}
		catch(DevideByMinusException e)
		{
			System.out.println("a");
		}
		catch(Exception e)
		{
			System.out.print(e.getMessage());	
		}
		finally
		{
			System.out.println("finally");
		}
		System.out.println("Program is Running!");
	}	
}

⌨️ 快捷键说明

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