Skip to content

Commit 6cd9efe

Browse files
authored
doc: book section on error handling (#393)
1 parent 75ff794 commit 6cd9efe

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

book/src/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
- [Defining metadata types in rust](./metadata_derive.md)
2020
- [Metadata and tables](./metadata_tables.md)
2121
- [Metadata schema](./metadata_schema.md)
22+
23+
* [Error handling](./error_handling.md)
2224

2325

2426
[Crate prelude](./prelude.md)

book/src/error_handling.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Error handling <img align="right" width="73" height="45" src="https://raw.githubusercontent.com/tskit-dev/administrative/main/logos/svg/tskit-rust/Tskit_rust_logo.eps.svg">
2+
3+
The error type is [`tskit::error::TskitError`](https://docs.rs/tskit/latest/tskit/error/enum.TskitError.html#).
4+
5+
This type implements `Display` and may thus be printed via:
6+
7+
```rust, noplayground, ignore
8+
let x = match operation() {
9+
Ok(y) => y,
10+
Err(e) => panic("{}", e);
11+
};
12+
```
13+
14+
The enum variant `TskitError::ErrorCode` represents integer return values from `tskit-c`.
15+
When printed via `Display`, the detailed error message is fetched.
16+
When printed via `Debug`, the numerical error code is shown.
17+

0 commit comments

Comments
 (0)