THE framework for doing Exceptional Programming in Swift
- All functions throw exceptions (
throws) - Functions never return (
-> Never {)
Functions look like this:
func name(...)throws->Never{...}import XPKitdependencies:[.package(url:"https://github.com/ExceptionalProgramming/XP-Swift",
from:"1.0.0")],targets:[.target(
name:"",
dependencies:["XPKit"]),]Exceptions are a class that should be thrown
ExceptionProgramTerminatedRuntimeExceptionFatalException
ValueException
All do/catch blocks should rethrow any unhandled exceptions
...}catchleterror{throw error }do{try...}catch _ as ProgramTerminated{}catchlet error{throw error }We understand that not all code is exceptional so we provide get<T>(from:) -> T which will extract the value from the thrown ValueException<T>
There is a provided add<T: Addable> function which throws the sum of all values. The Int and UInt families both conform to Addable