mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 17:41:41 +00:00
swift | fix style guidelines
This commit is contained in:
parent
39665aaad7
commit
62d4b1483b
@ -376,14 +376,14 @@ print("Имя :\(name)") // Имя: Яков
|
||||
|
||||
// Протокол `Error` используется для перехвата выбрасываемых ошибок
|
||||
enum MyError: Error {
|
||||
case BadValue(msg: String)
|
||||
case ReallyBadValue(msg: String)
|
||||
case badValue(msg: String)
|
||||
case reallyBadValue(msg: String)
|
||||
}
|
||||
|
||||
// фунции помеченные словом `throws` должны вызываться с помощью `try`
|
||||
func fakeFetch(value: Int) throws -> String {
|
||||
guard 7 == value else {
|
||||
throw MyError.ReallyBadValue(msg: "Действительно плохое значение")
|
||||
throw MyError.reallyBadValue(msg: "Действительно плохое значение")
|
||||
}
|
||||
|
||||
return "тест"
|
||||
@ -401,7 +401,7 @@ func testTryStuff() {
|
||||
do {
|
||||
// обычно try оператор, позволяющий обработать ошибку в `catch` блоке
|
||||
try fakeFetch(value: 1)
|
||||
} catch MyError.BadValue(let msg) {
|
||||
} catch MyError.badValue(let msg) {
|
||||
print("Ошибка: \(msg)")
|
||||
} catch {
|
||||
// все остальное
|
||||
|
@ -361,14 +361,14 @@ print("Name is \(name)") // Name is Them
|
||||
|
||||
// The `Error` protocol is used when throwing errors to catch
|
||||
enum MyError: Error {
|
||||
case BadValue(msg: String)
|
||||
case ReallyBadValue(msg: String)
|
||||
case badValue(msg: String)
|
||||
case reallyBadValue(msg: String)
|
||||
}
|
||||
|
||||
// functions marked with `throws` must be called using `try`
|
||||
func fakeFetch(value: Int) throws -> String {
|
||||
guard 7 == value else {
|
||||
throw MyError.ReallyBadValue(msg: "Some really bad value")
|
||||
throw MyError.reallyBadValue(msg: "Some really bad value")
|
||||
}
|
||||
|
||||
return "test"
|
||||
@ -385,7 +385,7 @@ func testTryStuff() {
|
||||
do {
|
||||
// normal try operation that provides error handling via `catch` block
|
||||
try fakeFetch(value: 1)
|
||||
} catch MyError.BadValue(let msg) {
|
||||
} catch MyError.badValue(let msg) {
|
||||
print("Error message: \(msg)")
|
||||
} catch {
|
||||
// must be exhaustive
|
||||
|
Loading…
Reference in New Issue
Block a user