/*
自定义异常判断歌曲播放是否存在
*/
class PlayerTest
{
public static void main(String[] args) //实验测试
{
try{Player player1=new Player();
player1.play(9);
}
catch (NoThisSoundException e)
{System.out.println(e.getMessage());
}
}
}
class NoThisSoundException extends Exception//自定义异常
{ NoThisSoundException()
{super();}
NoThisSoundException(String message)
{super(message);
}
}
class Player //
{public void play(int index)throws NoThisSoundException{
if (index<10)
throw new NoThisSoundException("您播放的歌曲不存在") ;
}
} |
|