Skip to main content
9 events
when toggle format what by license comment
May 24, 2011 at 14:23 comment added Winston Ewert @Birfl, or I could use a language which throws exceptions by default and get the same effect without subclassing. I just don't see any case where I'd rather have invalid values like nulls returned rather then an exception.
May 24, 2011 at 11:20 comment added Blrfl @Winston Ewert: If the container doesn't throw exceptions and you want them (and there's nothing wrong with that), subclass it, make it throw exceptions and use the subclass. Then you've covered your bases. Problem solved.
May 24, 2011 at 11:14 comment added Blrfl @Job: Methods should work first. The industry term for something that doesn't handle unusual results in the name of keeping a method short is "busted code." The industry term for having to correct a problem in production that was intentionally ignored during development is "professionally embarrassing." To put it another way: I warn you that I'm about to hand you a red-hot poker and you grab it without finding the cool end, you run a good chance of getting burned.
May 23, 2011 at 23:35 comment added Winston Ewert To put this another way, with exceptions I have to explicitly handle the unusual case or else my program dies right away. With null references if the code doesn't explicitly handle the unusual case, it will try to limp on. I think it better to take the fail now case.
May 23, 2011 at 23:33 comment added Winston Ewert @Birfl, sometimes I don't want to handle the case where a null would be natural to return. For example, suppose I have a container mapping keys to values. If my logic guarantees that I never attempt to read values I didn't first store, then I should never get null returned. In that case, I'd much rather have an exception which provides as much information as possible to indicate what went wrong, rather then returning a null to fail mysteriously someplace else in the program.
May 23, 2011 at 23:13 comment added Aaronaught @Job: What if you don't have a debugger? You do realize that 99.99% of the time your application is going to be running in a release environment? When that happens, you're going to wish that you'd used a more meaningful exception. Your app may still have to fail and annoy the user, but at least it will output debug information that will enable you to promptly track down the issue, thus keeping said annoyance to a minimum.
May 23, 2011 at 23:08 comment added Job @Blrfl, ideally methods are quite short, and thus it is easy to figure out exactly where the problem is happening. A good debugger can usually hunt a null reference exception well, even if the code is long. What am I supposed to do if I am trying to read a critical setting from a registry, which is not there? My registry is messed up and I am better of failing and annoying the user, than silently recreating a node and setting it to default. What if a virus did this? So, if I get a null, should I throw a specialized exception or just let it rip? With short methods what is the big difference?
May 23, 2011 at 21:14 comment added Blrfl Failure to handle a NULL would be willful ignorance of the interface between your code and whatever returned it. Developers who would make that mistake would make others in a language that doesn't do NULLs.
May 23, 2011 at 19:30 history answered John Gaines Jr. CC BY-SA 3.0