carfield.com.hk suggestion.txt 2021-01-27T13:55:59Z 2021-01-27T13:55:59Z <br/>With nice examples - <a href="http://www.javaspecialists.eu/archive/Issue162.html">http://www.javaspecialists.eu/archive/Issue162.html</a> <br/><br/>Try to do better working than log and quit - <a href="http://blog.objectmentor.com/articles/2009/01/05/abstracting-away-from-exceptions">http://blog.objectmentor.com[..]9/01/05/abstracting-away-from-exceptions</a> <br/><br/><a href="http://www.makinggoodsoftware.com/2011/01/26/how-to-manage-exceptions-in-java-4-basic-considerations/">http://www.makinggoodsoftware.com[..]ceptions-in-java-4-basic-considerations/</a> <br/><br/>Exception Patterns - <a href="http://c2.com/cgi/wiki?ExceptionPatterns">http://c2.com/cgi/wiki?ExceptionPatterns</a> <br/><br/>The Scourge of Error Handling, "go" experience - <a href="http://www.drdobbs.com/architecture-and-design/the-scourge-of-error-handling/240143878?cid=DDJ_nl_upd_2012-12-05_h&elq=2c4502fb959647fd9ad16dc5c0f7d75d">http://www.drdobbs.com[..]5_h&elq=2c4502fb959647fd9ad16dc5c0f7d75d</a> <br/><br/><a href="http://www.flowstopper.org/2013/11/java-should-i-assert-or-throw.html">http://www.flowstopper.org[..]13/11/java-should-i-assert-or-throw.html</a> <br/><br/><a href="https://vanilla-java.github.io/2016/06/21/Reviewing-Exception-Handling.html">https://vanilla-java.github.io[..]/06/21/Reviewing-Exception-Handling.html</a> <br/><br/><a href="https://blog.darrien.dev/posts/error-handling-in-java-is-error-prone/">https://blog.darrien.dev[..]s/error-handling-in-java-is-error-prone/</a> <br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2021-01-27T13:55:59Z Why use exception instead of error code.txt 2018-11-10T16:56:20Z 2018-11-10T16:56:20Z <br/>A detailed explanation - <a href="http://gamearchitect.net/Articles/ExceptionsAndErrorCodes.html">http://gamearchitect.net/Articles/ExceptionsAndErrorCodes.html</a> <br/><br/>What are exceptions? - <a href="https://binkley.blogspot.com/2018/11/what-are-exceptions.html">https://binkley.blogspot.com/2018/11/what-are-exceptions.html</a> <br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2018-11-10T16:56:20Z problem of using exception for control flow.txt 2008-06-25T01:59:02Z 2008-06-25T01:59:02Z <br/>Other than harder to read, this approach is easier to have side effect, consider the following case:<br/><pre><br/> // Code which fail<br/> public String service() { <br/> try {<br/> // a lot of other code.... <br/> return getRecord();<br/> } catch (SQLException re) {<br/> return "defaultRecord";<br/> }<br/> }<br/><br/> private String getRecord() throws SQLException {<br/> PreparedStatement ps = getConnection().prepareStatement("select something from sometable");<br/> try {<br/> final ResultSet rs = ps.executeQuery();<br/> try {<br/> if (rs.next())<br/> return rs.getString(1);<br/> else<br/> throw new NotFoundException();<br/> } finally {<br/> rs.close();<br/> }<br/> } finally {<br/> ps.close();<br/> }<br/><br/> // definition of NotFoundException, analog to IOException and FileNotFoundException<br/> public final class NotFoundException extends SQLException {....}<br/></pre><br/><br/>The idea is, for any database problem, just return default value. However, if someone change the interface of NotFoundException to<br/><br/> public final class NotFoundException extends RuntimeException {....}<br/><br/>Then it break service() silencely :-/ Some to it is better to have <br/><br/><pre><br/> // Code which fail<br/> public String service() {<br/> try {<br/> // a lot of other code....<br/> return getRecord() == null ? "defaultRecord" : getRecord();<br/> } catch (SQLException re) {<br/> // proper exception handling<br/> }<br/> }<br/><br/> private String getRecord() throws SQLException {<br/> PreparedStatement ps = getConnection().prepareStatement("select something from sometable");<br/> try {<br/> final ResultSet rs = ps.executeQuery();<br/> try {<br/> if (rs.next())<br/> return rs.getString(1);<br/> else<br/> return null;<br/> } finally {<br/> rs.close();<br/> }<br/> } finally {<br/> ps.close();<br/> }<br/></pre><br/><br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2008-06-25T01:59:02Z Handle exception at event.txt 2008-03-17T17:25:24Z 2008-03-17T17:25:24Z <br/>To prevent no one notice there is problem<br/><br/>What the code is trying to do is make sure is that any exception thrown is brought to the attention of the user. I’ve been looking at a few approaches to help catch and handle these exceptions without the developer having to explicitly catch them at the UI level.<br/>You can create your own EventQueue, and have it catch uncaught exceptions when dispatching methods<br/><br/><a href="http://www.magpiebrain.com/blog/2004/07/21/catching-uncaught-exceptions/">http://www.magpiebrain.com[..]2004/07/21/catching-uncaught-exceptions/</a> <br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2008-03-17T17:25:24Z anti-pattern of exception.txt 2007-07-12T08:20:21Z 2007-07-12T08:20:21Z <br/>Mostly agree, however, why do we need NoSuchMethodException? Why we don't just don't implement that method? If this is required by the interface, why we implement an interface but not complete the contact? <br/><br/><a href="http://today.java.net/pub/a/today/2006/04/06/exception-handling-antipatterns.html">http://today.java.net[..]/06/exception-handling-antipatterns.html</a> <a href="http://softarc.blogspot.com/2007/06/exception-handling-anti-patterns.html">http://softarc.blogspot.com[..]06/exception-handling-anti-patterns.html</a> <br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2007-07-12T08:20:21Z check or uncheck.txt 2007-06-13T17:14:39Z 2007-06-13T17:14:39Z <br/>Checked or unchecked? Not sure, seen all exception is unchecked are ok for me<br/><br/>To summarize Java orthodoxy: checked exceptions should be the norm. Runtime exceptions indicateprogramming errors.<br/>I used to subscribe to this view. However, after writing and working with thousands of catch blocks, I've come to the conclusion that this appealing theory doesn't always work in practice. I'm not alone. Since developing my own ideas on the subject, I've noticed that Bruce Eckel, author of the classic book Thinking in Java, has also changed his mind. Eckel now advocates the use of runtime exceptions as the norm, and wonders whether checked exceptions should be dropped from Java as a failed experiment<br/><br/><a href="http://www.mindview.net/Etc/Discussions/CheckedExceptions">http://www.mindview.net/Etc/Discussions/CheckedExceptions</a> <br/><br/>Other discussion of checked or unchecked - <a href="http://www.theserverside.com/news/thread.tss?thread_id=35586">http://www.theserverside.com/news/thread.tss?thread_id=35586</a> <a href="http://www.infoq.com/news/2007/05/removing-java-checked-exceptions">http://www.infoq.com[..]2007/05/removing-java-checked-exceptions</a> <br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2007-06-13T17:14:39Z handle exception in finally.txt 2007-02-27T04:31:48Z 2007-02-27T04:31:48Z <br/>This blog discuss the code at finally can affect code at catch block - <a href="http://mult.ifario.us/articles/2006/07/26/java-brain-teaser">http://mult.ifario.us/articles/2006/07/26/java-brain-teaser</a> <br/><br/><pre><br/>ExternalResource resource = resourceManager.open();<br/>Throwable e1 = null;<br/>try {<br/> // Use the resource (stream, db connection, ...)<br/>} catch (Throwable e) {<br/> e1 = e;<br/>} finally {<br/> try {<br/> resource.close();<br/> if (e1 != null) throw e1;<br/> } catch (Throwable e2) {<br/> // Pretend e2 doesn't already have a cause...<br/> if (e1 != null) e2.initCause(e1);<br/> throw e2;<br/> }<br/>}</pre><br/><a href="http://bagotricks.com/blog/2006/02/06/dropping-the-ball-er-exception/">http://bagotricks.com[..]06/02/06/dropping-the-ball-er-exception/</a> <br/><br/>or this, can be better looking<br/><br/><pre><br/>try {<br/> InputStream is = new FileOutputStream("hello.txt");<br/> try {<br/> is.write("hello");<br/> finally {<br/> is.close();<br/> }<br/>} catch (IOException e) {<br/> e.printStrackTrace();<br/>}<br/></pre><br/><a href="http://jroller.com/page/davinci?entry=finally_in_catch">http://jroller.com/page/davinci?entry=finally_in_catch</a> <br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2007-02-27T04:31:48Z Using stacktrace to know call hierarchy.txt 2006-02-24T08:14:21Z 2006-02-24T08:14:21Z <br/>Sometime it useful to know call hierarchy even if it is not exception case<br/><br/><a href="http://jroller.com/page/henribenoit?entry=where_am_i_called_from">http://jroller.com/page/henribenoit?entry=where_am_i_called_from</a> <br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2006-02-24T08:14:21Z cool exception message.shtml 2006-01-08T11:23:48Z 2006-01-08T11:23:48Z <br/>From a very good jpeg meta data extractor - <a href="http://drewnoakes.com/code/exif/">http://drewnoakes.com/code/exif/</a> mention the solution at exception message <pre> com.drew.metadata.MetadataException: Tag Image Width has not been set -- check using containsTag() first at com.drew.metadata.Directory.getInt(Unknown Source) </pre> <br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2006-01-08T11:23:48Z