« first day (2012 days earlier)      last day (2970 days later) » 

user114359
11:03 PM
0
Q: How do I use checked exceptions without violating the Law of Demeter?

SnowmanGiven a language that enforces checked exceptions (let us assume Java), how do we design an API that can throw exceptions without violating the Law of Demeter? To put this question in the proper scope, let us assume we are writing a publicly accessible jar library. Some of the classes will be ...

 
user114359
@Ixrec there it is.
 
@MichaelT You're everywhere, aren't you? Are you one of Duga's illegitimate children?
 
user55340
@RobertHarvey Just looking to see what drama is happening over on MSO that might spill over onto other sites... and was amused to find a familiar face at the center of one drama vortex.
 
user55340
(side bit - looking for eyeballs on github.com/the-whiteboard/the-whiteboard.github.io/blob/master/… before I move it to _posts )
 
@MichaelT I have developed a keen sense about when someone has already made up their mind about something.
 
11:06 PM
@Snowman thanks, upvoted
Don't use checked exceptions. — Robert Harvey 1 min ago
 
user55340
@Snowman I'm not an unfan of checked exceptions. I tend to find them useful between layers of application. The library down there throws an exception and this app needs to transform it into something nice for Spring, while that batch job needs to just bail out. Catching checked exceptions feels not worse than catching runtime exceptions.
 
user55340
The key thing with them is that they need to be usefully hierarchical. If they all just extend Exception, you're SOL.
 
user114359
@MichaelT I agree to some extent, I think the IOException I use as an example in that question is one where it makes a lot of sense to throw. But there have been plenty of times in my career I have had to deal with code that throws 12 different checked exceptions with no common ancestor other than java.lang.Exception and my response to all of them is "ask the user to retry or cancel" but I have to declare all 12 exceptions on 6 methods.
 
user114359
In other news, this HNQ over at DIY.SE is the type of solution I would get from my offshore team if they were designing houses instead of writing code:
 
user114359
1
Q: Can multiple pieces of crown molding be stacked / combined?

MarkIm trying to achieve a very ornate crown molding, and Ive gotten the look I want by gluing 3 pieces of crown molding together and it looks perfect. Ive used glue on my sample test run which is only about 1 foot in length. But this will be for a room thats about 12 feet long so Im sure the glue...

 
11:12 PM
yeah, forcing them all to be documented is begging for combinatorial explosions in non-trivial code, even if it looks cleaner in trivial examples
 
user114359
 
user55340
@Snowman then I rewrap them in my library with a sensible ancestry and a caused by field with the original exception.
 
user114359
@MichaelT ...which is sort-of my example three in the question
 
@MichaelT but do you wrap them in a new checked or a new unchecked exception?
 
user55340
@Ixrec if its going out of my layer / library, checked.
 
user114359
11:14 PM
But I would like to be clear this is not about checked vs. unchecked, that debate is as old as Java itself. I am asking how do I throw checked exceptions without violating the Law of Demeter?
 
user55340
But they're wrapped with useful ancestry so that you catch them with one catch.
 
user55340
@Snowman Exceptions are DTO that are being passed up a goto stack. The catch 'method' is implicitly called with it as an argument.
 
user55340
There is no LOD violation.
 
sounds like the start of an answer
go get your free rep
 
user114359
@MichaelT code further up (down?) the stack has to know implementation details about the inner workings of non-public classes in the library
 
user55340
11:16 PM
@Ixrec Yep, but its 15 min before I'm out the door... and @RobertHarvey reminded me I still need some cat litter.
 
CABAL INDEED
 
starred because this is the one and only time that accusation is sort of true
 
user114359
in all fairness that question is on the cusp of being too broad, but I think it can be answered in a reasonable amount of space.
 
user55340
@Snowman Why are they private? Why are you exposing private information in them? The type and public interface are all that you should be dealing with.
 
it's far better than 90% of the questions we get, so I'm not VTCing it
 
user55340
11:18 PM
@Ixrec 90? You're giving yourself a big buffer there.
 
I made up a number because I'm too apathetic to go look at the front page and count
 
user114359
@MichaelT but that's the point, I have to tell callers far from my part of the system that they have to catch an exception that might not be obvious at first
 
user114359
I think the argument against my point is that an exception specification is similar to a return type: nobody would argue that if A calls B calls C calls D and an int is returned back that is not violating LoD, so why would an exception? But in a sense an exception is sort of a side-effect inside D, like "I tried to give you your int but something else you don't know about failed spectacularly."
 
user114359
In other words, "some implementation detail you don't care about failed in a way you don't know, but every interface between us needs to know about it because none of us can handle that exception."
 
Either<int, Either<OutOfMemoryException, Either<DividebyZeroException, Either<IllegalArgumentException, ...>>>
it don't scale
 
11:28 PM
That chatroom has ventured into popcorn territory
 
am I missing a drama llama somewhere?
 
user114359
@Ixrec sounds like The Lounge is acting up again, maybe?
 
no one's linking it so I'll assume it's not actually popcorn-worthy
 
11:58 PM
wut
 

« first day (2012 days earlier)      last day (2970 days later) »