Comments on: Finally, a use for checked exceptions https://andypalmer.com/2011/11/finally-a-use-for-checked-exceptions/ Views on software, technology, consulting and business process Fri, 18 Nov 2011 07:13:00 +0000 hourly 1 https://wordpress.org/?v=6.4.3 By: Andy Palmer https://andypalmer.com/2011/11/finally-a-use-for-checked-exceptions/comment-page-1/#comment-1126 Fri, 18 Nov 2011 07:13:00 +0000 http://andypalmer.com/?p=272#comment-1126 In reply to Demian Alonso.

Good point. I have used Call Hierarchy, although when I read your comment, the idea that popped into my mind was “debugging”. 
I use “Find references in workspace (<ctrl><shift>g)” a lot while refactoring (particularly while deleting code), but not Call Hierarchy. I’m not sure why; I’ll investigate that feeling next time I’m doing something like this.

Also, yes, the point of this is to leverage the compiler to help make sure we’ve removed all traces of the original null. I hate null checks within code I control, as that is indicative of a bad citizen (see Good Citizen)

]]>
By: Demian Alonso https://andypalmer.com/2011/11/finally-a-use-for-checked-exceptions/comment-page-1/#comment-1125 Fri, 18 Nov 2011 01:29:00 +0000 http://andypalmer.com/?p=272#comment-1125 In reply to Andy Palmer.

Just a little contribution: Many ideas do have a way to search for references hierarchically. I now for sure that in Eclipse is called “call hierarchy”, but I am quite sure that on Idea is possible too, but I do not know the shortcuts 🙂

Still, the “it won’t compile”  technic does prevent you from missing any case.

]]>
By: Andy Palmer https://andypalmer.com/2011/11/finally-a-use-for-checked-exceptions/comment-page-1/#comment-1124 Thu, 17 Nov 2011 17:15:00 +0000 http://andypalmer.com/?p=272#comment-1124 In reply to Ricky Clarkson.

Good point. Although I would hope (for my sanity) that if there are catch everything blocks in the code, that they’re doing something sensible and I don’t need to go and change them at this point.
(I’ll probably go and rip them out at the soonest opportunity though 🙂 )

]]>
By: Andy Palmer https://andypalmer.com/2011/11/finally-a-use-for-checked-exceptions/comment-page-1/#comment-1123 Thu, 17 Nov 2011 17:14:00 +0000 http://andypalmer.com/?p=272#comment-1123 In reply to Thomas Kriegelstein.

Yes, although the advantage of this method is that it propagates _beyond the direct usages_.

]]>
By: Andy Palmer https://andypalmer.com/2011/11/finally-a-use-for-checked-exceptions/comment-page-1/#comment-1122 Thu, 17 Nov 2011 17:12:00 +0000 http://andypalmer.com/?p=272#comment-1122 In reply to Dileep Mandapam.

The advantage is that it highlights the direct and indirect usages of someMethod. Direct usages is obviously trivial, it’s the indirect usages where the bugs usually lie.

]]>
By: Dileep Mandapam https://andypalmer.com/2011/11/finally-a-use-for-checked-exceptions/comment-page-1/#comment-1121 Thu, 17 Nov 2011 16:28:00 +0000 http://andypalmer.com/?p=272#comment-1121 I don’t see any other advantage of this refactoring technique , other than finding usages of “someMethod”

]]>
By: Ricky Clarkson https://andypalmer.com/2011/11/finally-a-use-for-checked-exceptions/comment-page-1/#comment-1120 Thu, 17 Nov 2011 16:03:00 +0000 http://andypalmer.com/?p=272#comment-1120 You’ll need to remove all the catch (Exception e) and catch (Throwable t) instances that inevitably end up in large code bases precisely because of checked exceptions.

]]>
By: Andy Palmer https://andypalmer.com/2011/11/finally-a-use-for-checked-exceptions/comment-page-1/#comment-1119 Thu, 17 Nov 2011 15:46:00 +0000 http://andypalmer.com/?p=272#comment-1119 In reply to Alex Shneyderman.

If my someMethod() from above was used in another method like so:
public Result someOtherMethod() {
  if (someValue) {return something;}
  return someMethod();
}

then the value of someOtherMethod can also be null. So I also need to check the callers of that method, and so on, until I reach someone who either knows what the sensible thing to do with the value is or, I reach the extremities of the program (for example, the main loop or the request handler).

In the simple case, there isn’t a need to do this, but removing a null return should encompass the entire system, and this method ensures that this is the case.

You are correct about reflective calls, but I would hope that people using reflective calls were aware of the power (and therefore, danger) of that approach. 

]]>
By: Alex Shneyderman https://andypalmer.com/2011/11/finally-a-use-for-checked-exceptions/comment-page-1/#comment-1118 Thu, 17 Nov 2011 15:36:00 +0000 http://andypalmer.com/?p=272#comment-1118 In reply to Andy Palmer.

Hmm, I do not understand the second part of the explanation. The first five markers is all you need I would think. The rest is noise – although I do not understand why/how out of five usage places you would get another 20. If I have a method cal chain like so:
someUsageOfUsage -> usage -> npeProblem(this is the method where we add new Exception)I would only get trouble reports with the last portion of the chain (5 usages) pointing to the usage methods. The rest is noise, but I think compiler would not even complain aout the first link in the chain) and I woud not like to deal with that at all. So, I do not really see transitive use here. How?

Of course, it would be worth mentioning that the limitation of the trick is the loose coupling (reflective calls, JSP pages, etc). This method fails, and would only give the person using it a false sense of understanding.  

]]>
By: Thomas Kriegelstein https://andypalmer.com/2011/11/finally-a-use-for-checked-exceptions/comment-page-1/#comment-1117 Thu, 17 Nov 2011 14:39:00 +0000 http://andypalmer.com/?p=272#comment-1117 Changing an API and relying on the compiler to highlight the downstream changes is so clever. I might not have thought of that several years, like 10, before. Anyways kudos for sharing that stuff. And it works with your favorite IDE, e.g. Emacs, Notepad and vi too.

]]>