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

📄 exceptiondemo7.java

📁 JAVA程序设计课程中各章节的程序实例。
💻 JAVA
字号:
/**
*A simple exception handling program using throws
*"In the method declaration,
* specify the type of exception thst can be thrown,using the throws modifier"
*2004.12.26. xhcprince
*/

class Validation
{
	public void Inrange(int n) throws Exception
	{
		if(n>0 && n<1111)
		{
			System.out.println(n + " is in the range");
		}

		else
		{
			throw new Exception(n + " is not in the range");	//pay more attention here!
		}
	}
}

class exceptionDemo7
{
	public static void main(String args[])
	{
		int num = 0;

		num = Integer.parseInt("0");
		Validation obj = new Validation();

		try
		{
			obj.Inrange(num);
		}

		catch(Exception e)
		{
			System.out.println(e.toString());
			return;
		}

		System.out.println(num);
	}
}

⌨️ 快捷键说明

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