java 自定义异常处理示例

我是你の前男友 2018-10-15 04:55:47
class NoThisSongException extends Exception{ public NoThisSongException(String string){ super(string); } NoThisSongException(){ super(); } } class Player{ void play(int index) { try { if(index<10) System.out.println("输入正常"); else throw new NoThisSongException("您播放的歌曲不存在"); }catch(NoThisSongException e) { //e.getMessage(); System.out.print(e); } } } public class Test2 { public static void main(String[] args) { Player player = new Player(); player.play(11); } }
...全文
806 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
自己发的一个测试贴。

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧