Nothing can be taken for granted

jabber (jabber)
本文发表在 相约加拿大网上社区枫下论坛
Thanks a million for long-river and guest's posting. My postings are essentially for laymen and novices. Obviously, NullPointerException is a trivial one and
can be easily handled by a true Java programmer.
Guest pointed out the general solution:
Check if the Object reference is null before
you call its methods. For instance, people
need check if a network connection or dababase connection is still there before you call its corresponding close() method.

Another kinds of example is related to some
deprecated methods, which usually return a null in a server that implements a higher version of API. For instance, in most Java servlet engine that implements servlet API 2.2, if you run a servlet that uses getServlet method of the ServletContext interface, you will get a null. In the server-side Java programming, you don't always have luck to
see the StackTrace of a NullPointerException.

It seems to me nothing is really simple in this world. I have ever witnessed many Java learners stunned before NullPointerException. For a beginner, it is not straightforward to understand NullPointerException, let alone handling it gracefully.
更多精彩文章及讨论,请光临枫下论坛. 网址:
2000-9-5 -05:00

回到话题: Java Q&A (2) (compiled by jabber)

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论