首页 > 其他 > 详细

doGet() throws NamingException报错

时间:2017-04-23 00:02:46      阅读:401      评论:0      收藏:0      [点我收藏+]

     做一个通过JNDI查找资源的小练习,Context = new InitialContext(),发现NamingException异常,eclipse编辑器只有catch的提示,没有throws的提示,强行在doGet()方法后throws NamingException会报"Exception NamingException is not compatible with throws clause in HttpServlet.doGet(HttpServletRequest, HttpServletResponse)"。

     原因:查看HttpServlet中的doGet方法源码,

技术分享

根据方法重写的原则,子类重写父类方法时,抛出的异常不能超过父类的范畴,因此在本例中,只能throws ServletException和IOEXception,其他异常必须catch使得编译通过。

 

doGet() throws NamingException报错

原文:http://www.cnblogs.com/gujianzhe/p/6750047.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!