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.

Required fields*

5
  • So something that causes execution to jump to an easily identified place within the same function (goto) is considered "harmful", and something that causes execution to jump to who knows where in the calling hierarchy is "perfectly fine" even for common cases like boring old error handling(!)? Commented May 2, 2016 at 13:53
  • 1
    If you think about the scope of the execution it makes sense - throwing an exception immediately terminates the current function. One should take care to design their program structure such that exception handling happens at the most logical place, as if this is not the case, then you do end up with spaghetti-esque code, but given your designs are well structured, exceptions can be very powerful. Commented May 2, 2016 at 14:03
  • @Brendan The "who knows where" is part of what makes it good. It's generally bad for a function to know anything about the program outside itself. Commented May 11, 2016 at 1:27
  • Using exceptions for errors that are expected to be handles specifically is a mistake (even if it's one promoted by many languages). Exceptions should only be used for the controlled tear-down in case of an unexpected error (typically a bug). Excepted error conditions should be handled by returning the error (typically in a choice-type/tagged-union) Commented May 11, 2016 at 13:22
  • I wouldn't say it's necessarily a mistake - some languages offer exceptions and errors to make that distinction. Either way, one should always think carefully about which side of the line their case falls on - whether or should be returned by standard means, or through another mechanism. Whatever the means, if they give a decoupling of "standard" and "exceptional" control flows, you're probably on the right path Commented May 11, 2016 at 14:46