exception5.java

来自「课本异常处理实例。各种异常处理」· Java 代码 · 共 35 行

JAVA
35
字号
//自定义异常
class OverFlowException extends Exception
{
	OverFlowException()
	{
		System.out.println("此处数据有溢出,溢出类是OverFlowException");
	}
}

public class Exception5
{
	public static int x=100000;
	public static int multi() throws OverFlowException
	{
		int aim;
		aim=x*x*x;
		if(aim>2.15E9 || aim<0)
			throw new OverFlowException();
		else
			return x*x*x;
	}
	public static void main(String args[])
	{
		int y;
		try
		{
			y= multi();
			System.out.println("y="+y);
		}
		catch(OverFlowException e)
		{
			System.out.println(e);
		}
	}
}

⌨️ 快捷键说明

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