summaryrefslogtreecommitdiffstats
path: root/src/doc/book/listings/ch09-error-handling/listing-09-04
diff options
context:
space:
mode:
Diffstat (limited to 'src/doc/book/listings/ch09-error-handling/listing-09-04')
-rw-r--r--src/doc/book/listings/ch09-error-handling/listing-09-04/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch09-error-handling/listing-09-04/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch09-error-handling/listing-09-04/output.txt6
-rw-r--r--src/doc/book/listings/ch09-error-handling/listing-09-04/src/main.rs10
4 files changed, 28 insertions, 0 deletions
diff --git a/src/doc/book/listings/ch09-error-handling/listing-09-04/Cargo.lock b/src/doc/book/listings/ch09-error-handling/listing-09-04/Cargo.lock
new file mode 100644
index 000000000..1fa96b797
--- /dev/null
+++ b/src/doc/book/listings/ch09-error-handling/listing-09-04/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "error-handling"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch09-error-handling/listing-09-04/Cargo.toml b/src/doc/book/listings/ch09-error-handling/listing-09-04/Cargo.toml
new file mode 100644
index 000000000..c496db783
--- /dev/null
+++ b/src/doc/book/listings/ch09-error-handling/listing-09-04/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "error-handling"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch09-error-handling/listing-09-04/output.txt b/src/doc/book/listings/ch09-error-handling/listing-09-04/output.txt
new file mode 100644
index 000000000..f776a591c
--- /dev/null
+++ b/src/doc/book/listings/ch09-error-handling/listing-09-04/output.txt
@@ -0,0 +1,6 @@
+$ cargo run
+ Compiling error-handling v0.1.0 (file:///projects/error-handling)
+ Finished dev [unoptimized + debuginfo] target(s) in 0.73s
+ Running `target/debug/error-handling`
+thread 'main' panicked at 'Problem opening the file: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/main.rs:8:23
+note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
diff --git a/src/doc/book/listings/ch09-error-handling/listing-09-04/src/main.rs b/src/doc/book/listings/ch09-error-handling/listing-09-04/src/main.rs
new file mode 100644
index 000000000..69da109fe
--- /dev/null
+++ b/src/doc/book/listings/ch09-error-handling/listing-09-04/src/main.rs
@@ -0,0 +1,10 @@
+use std::fs::File;
+
+fn main() {
+ let greeting_file_result = File::open("hello.txt");
+
+ let greeting_file = match greeting_file_result {
+ Ok(file) => file,
+ Err(error) => panic!("Problem opening the file: {:?}", error),
+ };
+}