public class Defind {
public static void main(String[] args) {
try
{
throw new DefindException("异常");
}
catch(DefindException e)
{
System.out.println(e);
}
}
class DefindException extends Exception
{
public DefindException(String msg)
{
super(msg);
}
}
}
class DefindException增加static就行了
static class DefindException extends Exception
内嵌类的实例化
楼上说的对
一种throw new Defind().new DefindException("异常");
一种static class DefindException extends Exception
一种class DefindException extends Exception{public DefindException(String msg){super(msg);}}这段代码挪到Defind类代码外部