1. 16
  1.  

  2. 3

    I found this a little concerning, under ‘New Features’: “The new error handling model in Swift 2.0 will instantly feel natural, with familiar try, throw, and catch keywords.”

    Doesn’t Swift use error encompassing ADTs? Exception handling keywords seem like a step back. Hopefully someone with more Swift experience can speak to this.

    1. 4

      Swift doesn’t have a ‘blessed’ ADT for error handling, although it’s possible to build your own. Compiler limitations before the announcement of Swift 2.0 made it rather tedious, though, because declaring an enum (ADT) type with more than one generic type parameter didn’t work properly. We had Optional (e.g. Maybe), but not a usable Either.

      Swift’s new error system involves the compiler performing exhaustiveness checking at compile-time. The official documentation seems to encourage using enums as error types, since enums can easily be checked for exhaustiveness. (There are no dedicated exception classes or types; any type that conforms to the ErrorType protocol/interface can serve as an error, in addition to whatever else it is meant to do.)

      Even so, not everyone is happy with the new error system. There are quite a few developers who would have preferred better monadic support over special-purpose language constructs like the do-catch statement and other new features.