只定义异常类和Runtime异常类

package frank;
import java.lang.*;

/**
 * 只定义异常类和Runtime异常类
 * */
public class App
{
	public static void main(String[] args)
	{
		try
		{
			get(args);
		}
		catch(UserException e)
		{
			System.out.println(e.getMessage()+"u");
		}
		catch(Exception e)//子类放前面,父类放后面。
		{
			System.out.println(e.getMessage()+"s");
		}
		get("1");//运行时异常可以捕获,也可以不用捕获!

	}
	public static void get(String[] args)throws UserException
	{
		if(args.length<=0)
		throw new UserException("1");
	}
	public static void get(String s)
	{
		throw new UserRuntimeException("运行时异常!");
	}
}
class UserException extends Exception//定义一个异常类
{
	public UserException()
	{
		
	}
	public UserException(String msg)
	{
		super(msg);
	}

}
class UserRuntimeException extends RuntimeException//定义一个运行时异常类
{
	public UserRuntimeException()
	{
	
	}
	public UserRuntimeException(String msg)
	{
		super(msg);
	}
     public UserRuntimeException(Throwable t)//jdk 1.4后增加的一个功能。
    {
      super(t);
    }
}

  

posted on 2013-10-25 15:32  wp456  阅读(182)  评论(0)    收藏  举报

导航