📄 exceptiondemo8.java
字号:
/**
*A simple user-defined exception handling program.pay more attention!
*2004.12.27. xhcprince
*"The return statement may be used in the catch block to return the control
* back to the exception block.If we use return in the catch block,the statement after the catch"
* block will not be displayed!"
*/
class InrangeException extends Exception
{
InrangeException(int wrongNum)
{
super(wrongNum + " is not a valid number");
}
}
class Validation
{
public void Inrange(int num) throws Exception
{
if(num>0 && num<1111)
{
System.out.println("n is in the range");
}
else
{
throw new InrangeException(num);
}
}
}
class exceptionDemo8
{
public static void main(String args[])
{
int num = 0;
num = Integer.parseInt("0"); //Input from command prompt!
Validation obj = new Validation();
try
{
obj.Inrange(num);
}
catch(Exception e)
{
System.out.println(e.toString());
return; //the num will not be displayed!
}
System.out.print(num);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -