import java.util.InputMismatchException;
import java.util.Scanner;
public class IsException {
public void exceptionHanding()
{
Scanner scanner=new Scanner(System.in);
try {
System.out.println("为error赋值:");
int error=0;
try {
error=scanner.nextInt();
}catch(InputMismatchException e)
{
System.out.println(e.toString());
System.out.println("error值错误");
error=-1;
}
if(error==-1)
{
throw new Exception();
}
else
{
System.out.println("程序正常!");
}
}catch(Exception e)
{
System.out.println(e.toString());
System.out.println("程序出错了!");
}
finally
{
scanner.close();
}
}
public static void main(String[] args) {
new IsException().exceptionHanding();
}
}
import java.util.InputMismatchException;
import java.util.Scanner;
public class IsExceptionUpdate {
public void push() throws InputMismatchException,Exception
{
Scanner scanner=new Scanner(System.in);
System.out.println("为error赋值:");
int error=-1;
error=scanner.nextInt();
scanner.close();
if(error==-1)
{
throw new Exception();
}
else
{
System.out.println("程序正常!");
}
}
public static void main(String[] args) {
try
{
new IsExceptionUpdate().push();
}
catch(InputMismatchException e)
{
System.out.println(e.toString());
System.out.println("error值错误");
}
catch(Exception e)
{
System.out.println(e.toString());
System.out.println("程序出错了!");
}
}
}