Correct error handling example

This commit is contained in:
Steven Fackler 2014-03-09 15:25:38 -07:00
parent 58571cab26
commit 539fe2d677

View File

@ -158,11 +158,11 @@ 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"), Err(PgDbError(PostgresDbError { code: SyntaxError, .. })) =>
PgDbError(SyntaxError) => println!("Invalid query syntax"), println!("Invalid query syntax"),
_ => println!("A bad thing happened: {}", err), _ => println!("A bad thing happened: {}", err),
} }
} }
``` ```