Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • That's a good point about people ignoring return values. Sure, an exception can be caught and ignored too but I think the idea of an exception being thrown suggests that something happened that wasn't expected - such as the API being down or the shipment failing for some other reason. Commented May 27, 2017 at 2:34
  • @Lock Yes, exceptions can be caught and ignored. The primary difference is that the person calling the method with a return code needs to write code to handle success or failure, while the person calling the method needs to do nothing. If it works the next line will be executed but if it fails the exception continues. It takes work to ignore exceptions, but no work to ignore return codes. That's a good point and really at the heart of my answer. Commented May 27, 2017 at 13:27
  • @Lock However, an API being down unexpectedly doesn't really factor into the choice of throwing an exception or not. Its a design choice you make when you create the method. You may have an UpdateCache method that calls the API, and your design depends on the cache being updated to succeed. In that case, your method might throw if the API is down. But it could also be that your cache is a cache and for your design its ok if you use cached data which is a bit stale. In that case UpdateCache might try the API if it fails the caller won't know, because that's how the method was designed. Commented May 27, 2017 at 13:31
  • @Lock So it really boils down to what decision did the programmer make when they created the methods contract. Hopefully the decision is documented somewhere too. :-) Commented May 27, 2017 at 13:32
  • 1
    @Andy Hopefully the decision isn't just documented somewhere but where you can actually find it. Commented May 27, 2017 at 19:17