Correct error handling example
This commit is contained in:
parent
58571cab26
commit
539fe2d677
@ -158,10 +158,10 @@ methods, there is a second variant prefixed with `try_` which returns a
|
|||||||
```rust
|
```rust
|
||||||
match conn.try_execute(query, params) {
|
match conn.try_execute(query, params) {
|
||||||
Ok(updates) => println!("{} rows were updated", updates),
|
Ok(updates) => println!("{} rows were updated", updates),
|
||||||
Err(err) => match err.code {
|
Err(PgDbError(PostgresDbError { code: NotNullViolation, .. })) =>
|
||||||
PgDbError(NotNullViolation) =>
|
|
||||||
println!("Something was NULL that shouldn't be"),
|
println!("Something was NULL that shouldn't be"),
|
||||||
PgDbError(SyntaxError) => println!("Invalid query syntax"),
|
Err(PgDbError(PostgresDbError { code: SyntaxError, .. })) =>
|
||||||
|
println!("Invalid query syntax"),
|
||||||
_ => println!("A bad thing happened: {}", err),
|
_ => println!("A bad thing happened: {}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user