目录
目录README.md

XPKit

THE framework for doing Exceptional Programming in Swift

What is Exceptional Programming

  • All functions throw exceptions (throws)
  • Functions never return (-> Never {)

Functions look like this:

func name(...) throws -> Never {
    ...
}

Importing

import XPKit
dependencies: [
    .package(url: "https://github.com/ExceptionalProgramming/XP-Swift",
             from: "1.0.0")
],
targets: [
    .target(
        name: "",
        dependencies: [
            "XPKit"
        ]),
]

Exceptions

Exceptions are a class that should be thrown

  • Exception
    • ProgramTerminated
    • RuntimeException
      • FatalException
    • ValueException

All do/catch blocks should rethrow any unhandled exceptions

...
} catch let error { throw error }

main()

do {
    try ...
} catch _ as ProgramTerminated {
} catch let error { throw error }

Getting values

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>

Addition

There is a provided add<T: Addable> function which throws the sum of all values. The Int and UInt families both conform to Addable

关于
41.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号