• (disco) in reply to anonymous234
    anonymous234:
    But I can't even imagine how you'd type a function call like that.

    Logically, it's a disjoint union of the type of the errors and the type of the ordinary results. I don't know how you express that in Go, but it'd be trivial in Haskell or one of the other functional programming languages.

  • (disco) in reply to ScholRLEA
    ScholRLEA:
    It means that exceptions are a backstop for emergencies, not for ordinary flow of control. They are one tool in the toolbox, but not one which needs to be used every time.

    I disagree. If it is an emergency the application should exit. The point of raising exceptions is that we hope the consumer may know a way to to handle the situation. Of course the exceptions must be caught as early as possible, to handle the situation.

    make_file("some/log/path/file")
    

    If exceptions are well documented, I will know that make_file may throw OSError if the path does not exist. Now my application may expect that the path may not exist, so I can catch only OSError and try to first mkdir("some/log/path", recursive=True) then call make_file again. If I get an unexpected exception, that will result in application getting killed with a nice stack trace.

  • (disco) in reply to anonymous234
    anonymous234:
    Well, that's how Go does it (not that anyone here likes Go)

    Now I do not! that seems like a weird language.

  • (disco) in reply to dse
    dse:
    Of course the exceptions must be caught as early as possible, to handle the situation.

    Strictly, they should be caught at the point that knows how to handle the exceptional situation. What point is that? It depends on the application. Sometimes the right way to handle it is to just use the next filename from the list. Sometimes the right way is to show a dialog box to the user. Sometimes it is to write a frantic message to the log and bomb the whole OS out. (I hope I don't hit that last one often, but if the hardware is up the spout, that's probably for the best; a failing motherboard is very bad news.)

  • (disco) in reply to dkf

    Except that you can return an error as well as a valid result, such as when you're reading from a socket and the socket gets cut off halfway through the read. You still return the number of bytes read, but you also return an error.

  • (disco) in reply to ben_lubar
    ben_lubar:
    Except that you can return an error as well as a valid result

    That depends on how you're modelling the failure mode, of course…

  • (disco) in reply to dkf

    I have a serious question. In a language with checked exceptions, what happens when the called method (in a updated version) adds a new exception? Is that correctly considered a breaking change, like, for every single app? Or just apps start crashing when they didn't used to?

Leave a comment on “The Self Test”

Log In or post as a guest

Replying to comment #:

« Return to Article