<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Being Cellfish : Java</title><link>http://blogs.msdn.com/cellfish/archive/tags/Java/default.aspx</link><description>Tags: Java</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Exceptions or not?</title><link>http://blogs.msdn.com/cellfish/archive/2009/10/01/exceptions-or-not.aspx</link><pubDate>Fri, 02 Oct 2009 08:01:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9902199</guid><dc:creator>cellfish</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/cellfish/comments/9902199.aspx</comments><wfw:commentRss>http://blogs.msdn.com/cellfish/commentrss.aspx?PostID=9902199</wfw:commentRss><description>&lt;P&gt;I've always had mixed feelings for exceptions. First of all exceptions should only be used for exceptional things, not things that are expected. For example if you open a file it may fail for several reasons; it does not exists, you do not have rights to open it or it may be locked. These are all perfectly reasonable errors and throwing an exception for these failures is in my opinion not a great API design. If there are other methods to check for all these circumstances it might be OK but not optimal. A reasonable compromise is to have a TryOpen method which never throws an exception. This gives the user of the API&amp;nbsp;the option of letting file open errors being expected or fatal.&lt;/P&gt;
&lt;P&gt;Because exceptions should only be thrown for exceptional circumstances there should be no reason to catch them other in the application's main loop unless you can add information to the error in which case you want to wrap and throw a better exception. The exception to this rule is when you use an API (such as file open mentioned before) that throws for pretty common error cases you want to ignore.&lt;/P&gt;
&lt;P&gt;Another thing I don't like with exceptions is the fact that you (in C++ and C#, Java is better here) get no help from the compiler to know what types of exceptions a function may call. So in C++ and C# you may think you catch everything you need but you really don't which leads to unwanted behavior in your application. It is just too easy to get into a situation where you think a number of lines are going to be executed but they're not for some exception.&lt;/P&gt;
&lt;P&gt;However if you use return codes (as you would in a C program) you get your code cluttered with "if (previous called failed) handle error" which hides what the code really does. This can be hidden using macros to handle errors (ex: result = DoSomething ON_FAIL_RETURN(result); ). And if there is no error handling it is hard to know what happens when the next line is executed even though there was an error.&lt;/P&gt;
&lt;P&gt;Using exceptions is also a kind of "I failed and I hope somebody else somewhere can handle it" while the use of return codes defines a clear contract "I failed and you who called me must handle it". So even though exceptions are convenient, return codes feel more defensive, i.e. are easier to get right resulting in less bugs but sometimes at the cost of less clear code. As usual the mix of both approaches is probably the best. But there are more alternatives. If you use &lt;A href="http://blog.objectmentor.com/articles/2009/01/05/abstracting-away-from-exceptions" target=_blank mce_href="http://blog.objectmentor.com/articles/2009/01/05/abstracting-away-from-exceptions"&gt;adverse as described by Feathers&lt;/A&gt; I'm prepared to accept exceptions to a much larger degree because they're being handled immediately so it reminds of the return code approach.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9902199" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/cellfish/archive/tags/Java/default.aspx">Java</category><category domain="http://blogs.msdn.com/cellfish/archive/tags/.Net/default.aspx">.Net</category><category domain="http://blogs.msdn.com/cellfish/archive/tags/C_2B002B00_/default.aspx">C++</category><category domain="http://blogs.msdn.com/cellfish/archive/tags/Development/default.aspx">Development</category></item><item><title>Selenium the test tool</title><link>http://blogs.msdn.com/cellfish/archive/2008/04/09/selenium-the-test-tool.aspx</link><pubDate>Wed, 09 Apr 2008 21:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8373032</guid><dc:creator>cellfish</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/cellfish/comments/8373032.aspx</comments><wfw:commentRss>http://blogs.msdn.com/cellfish/commentrss.aspx?PostID=8373032</wfw:commentRss><description>&lt;P&gt;I almost forgot that before the &lt;A class="" title="BDD and DDD" href="http://blogs.msdn.com/cellfish/archive/2008/04/09/bdd-and-ddd.aspx" mce_href="http://blogs.msdn.com/cellfish/archive/2008/04/09/bdd-and-ddd.aspx"&gt;BDD/DDD presentation&lt;/A&gt;, there was a presentation about &lt;A class="" title="Selenium - the test tool" href="http://en.wikipedia.org/wiki/Selenium_%28software%29" target=_blank mce_href="http://en.wikipedia.org/wiki/Selenium_%28software%29"&gt;Selenium&lt;/A&gt;. I didn't forget it because it was a bad presentation but because the following presentation was so good...&lt;/P&gt;
&lt;P&gt;I've never had any good experiences with tools for automatic testing but I must confess that Selenium looks nice.&amp;nbsp; At least if you want to add regression tests to an existing GUI. And it is a web based GUI. So if those two fact apply to you, you should take a look at Selenium I think.&lt;/P&gt;
&lt;P&gt;Selenium is good at recording actions and create test code. And it creates test code for unit tests frameworks such as NUnit and a whole bunch of other languages such as Python, Java, Ruby, PHP and more. However there seems to be some stability problems at the moment. According to the presenter (I have not found a link to verify this); Google have more than 51000 selenium tests in their projects. 96% of the tests run with no problem, 2% have problems due to confirmed bugs in Selenium and the last 2% are tests failing where the reason&amp;nbsp; is unclear (Selenium vs the code tested). &lt;/P&gt;
&lt;P&gt;This is a common problem I see when I work with open source. Open source applications are typically quite useful and easy to use 99% of the time. But I always tend to end up needing the last percent which is never implemented or have bugs. And the reason for this is usually that no one have bothered to implement the last tricky advanced feature I end up needing. You probably wanna know why I do not sit down and implement that feature and contribute it back to the open source community. Well that is a whole other topic and I will write about that it the near future.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8373032" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/cellfish/archive/tags/PHP/default.aspx">PHP</category><category domain="http://blogs.msdn.com/cellfish/archive/tags/Test/default.aspx">Test</category><category domain="http://blogs.msdn.com/cellfish/archive/tags/Java/default.aspx">Java</category><category domain="http://blogs.msdn.com/cellfish/archive/tags/Ruby/default.aspx">Ruby</category><category domain="http://blogs.msdn.com/cellfish/archive/tags/Python/default.aspx">Python</category><category domain="http://blogs.msdn.com/cellfish/archive/tags/Open+source/default.aspx">Open source</category><category domain="http://blogs.msdn.com/cellfish/archive/tags/.Net/default.aspx">.Net</category><category domain="http://blogs.msdn.com/cellfish/archive/tags/Tools/default.aspx">Tools</category></item></channel></rss>