当前位置: 技术问答>java相关
请问java里能自己定义新的Exception吗?
来源: 互联网 发布时间:2015-10-11
本文导语: 如果可以, 怎么定义? 并且怎么在try-catch模块中用到他呢? ( 是不是牵扯到了虚拟机的问题??那就没话说了:( ) | public class AccountException extends Exception { public AccountException()...
如果可以,
怎么定义?
并且怎么在try-catch模块中用到他呢?
( 是不是牵扯到了虚拟机的问题??那就没话说了:( )
怎么定义?
并且怎么在try-catch模块中用到他呢?
( 是不是牵扯到了虚拟机的问题??那就没话说了:( )
|
public class AccountException extends Exception
{
public AccountException()
{
super("catch AccountException");
}
public AccountException(String msg)
{
super(msg);
}
public AccountException(Exception e)
{
super(e.getMessage());
}
public AccountException(Throwable cause)
{
super(cause.getMessage());
}
}
{
public AccountException()
{
super("catch AccountException");
}
public AccountException(String msg)
{
super(msg);
}
public AccountException(Exception e)
{
super(e.getMessage());
}
public AccountException(Throwable cause)
{
super(cause.getMessage());
}
}
|
if(发生erorr)
{
AccountException ex1 = new AccountException ("错误名称");
throw ex;
}
{
AccountException ex1 = new AccountException ("错误名称");
throw ex;
}