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

📄 myexceptest.java

📁 关于java异常处理方面的小例子
💻 JAVA
字号:
package myException;

import java.io.*;

class OutBoundsException extends Exception
{
	OutBoundsException(String mes)
	{
		super(mes);
	}
}

class Check
{
	String ChecktheNum(int n)throws OutBoundsException
	{
		Integer N=new Integer(n);
		if(n>30||n<20)
			throw new OutBoundsException("the number is out of bound");
		else
			return "the number"+N.toString()+"is in the bound";

	}
}

public class MyExcepTest 
{

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		// TODO 自动生成方法存根
       try
       {
    	   Check c=new Check();
    	   System.out.println("以下是合法数据");
    	   System.out.println(c.ChecktheNum(25));
    	   System.out.println("以下是非法数据");
    	   System.out.println(c.ChecktheNum(5));
       }
       catch(OutBoundsException e)
       {
    	   System.out.println(e.toString());
       }
	}

}

⌨️ 快捷键说明

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