mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-27 04:14:21 +00:00
SE-0276 Multi-Pattern Catch Clauses
This commit is contained in:
1 parent
038c320f07
commit
ff126c1543
4 files changed
+8
-11
No files matched your search
@@ -161,7 +161,7 @@ With such a setup, you may still get `SQLITE_BUSY` (5, "database is locked") err
|
||||
```swift
|
||||
do {
|
||||
try dbPool.write { db in ... }
|
||||
} catch let error as DatabaseError where error.resultCode == .SQLITE_BUSY {
|
||||
} catch DatabaseError.SQLITE_BUSY {
|
||||
// Another process won't let you write. Deal with it.
|
||||
}
|
||||
```
|
||||
@@ -251,7 +251,7 @@ See https://developer.apple.com/documentation/xcode/understanding-the-exception-
|
||||
```swift
|
||||
do {
|
||||
try dbPool.write { db in ... }
|
||||
} catch let error as DatabaseError where error.isInterruptionError {
|
||||
} catch DatabaseError.SQLITE_INTERRUPT, DatabaseError.SQLITE_ABORT {
|
||||
// Oops, the database is suspended.
|
||||
// Maybe try again after database is resumed?
|
||||
}
|
||||
|
||||
@@ -6909,12 +6909,12 @@ try dbQueue.write { db in
|
||||
} // throws SQLITE_ABORT
|
||||
```
|
||||
|
||||
You can catch both `SQLITE_INTERRUPT` and `SQLITE_ABORT` errors with the `DatabaseError.isInterruptionError` property:
|
||||
You can catch both `SQLITE_INTERRUPT` and `SQLITE_ABORT` errors:
|
||||
|
||||
```swift
|
||||
do {
|
||||
try dbPool.write { db in ... }
|
||||
} catch let error as DatabaseError where error.isInterruptionError {
|
||||
} catch DatabaseError.SQLITE_INTERRUPT, DatabaseError.SQLITE_ABORT {
|
||||
// Oops, the database was interrupted.
|
||||
}
|
||||
```
|
||||
@@ -8366,10 +8366,7 @@ When your application should be able to run in the background on a locked device
|
||||
```swift
|
||||
do {
|
||||
try ...
|
||||
} catch let error as DatabaseError where
|
||||
error.resultCode == .SQLITE_IOERR ||
|
||||
error.resultCode == .SQLITE_AUTH
|
||||
{
|
||||
} catch DatabaseError.SQLITE_IOERR, DatabaseError.SQLITE_AUTH {
|
||||
// Handle possible data protection error
|
||||
}
|
||||
```
|
||||
|
||||
@@ -190,7 +190,7 @@ class DatabaseConfigurationTests: GRDBTestCase {
|
||||
_ = s2.wait(timeout: .distantFuture)
|
||||
try dbQueue2.inTransaction(.exclusive) { db in return .commit }
|
||||
XCTFail("Expected error")
|
||||
} catch let error as DatabaseError where error.resultCode == .SQLITE_BUSY {
|
||||
} catch DatabaseError.SQLITE_BUSY {
|
||||
} catch {
|
||||
XCTFail("\(error)")
|
||||
}
|
||||
@@ -240,7 +240,7 @@ class DatabaseConfigurationTests: GRDBTestCase {
|
||||
// _ = s2.wait(timeout: .distantFuture)
|
||||
// try dbQueue2.inTransaction(.exclusive) { db in return .commit }
|
||||
// XCTFail("Expected error")
|
||||
// } catch let error as DatabaseError where error.resultCode == .SQLITE_BUSY {
|
||||
// } catch DatabaseError.SQLITE_BUSY {
|
||||
// } catch {
|
||||
// XCTFail("\(error)")
|
||||
// }
|
||||
|
||||
@@ -37,7 +37,7 @@ class DatabaseReaderTests : GRDBTestCase {
|
||||
try db.execute(sql: "CREATE TABLE t (id INTEGER PRIMARY KEY)")
|
||||
}
|
||||
XCTFail("Expected error")
|
||||
} catch let error as DatabaseError where error.resultCode == .SQLITE_READONLY {
|
||||
} catch DatabaseError.SQLITE_READONLY {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user