# การจัดการข้อผิดพลาด (Rust) > Result, Option, unwrap, expect, ?, ข้อผิดพลาดที่กำหนดเอง, การส่งต่อข้อผิดพลาด - 18 คำถามสัมภาษณ์ - Junior - [คำถามสัมภาษณ์: Rust](https://sharpskill.dev/th/technologies/rust/interview-questions.md) ## 1. ชนิดข้อมูลใดของ Rust แทนค่าที่อาจมีอยู่หรือไม่มีอยู่ก็ได้? **คำตอบ** Option เป็น enum ที่อาจเป็น Some(T) ซึ่งเก็บค่าไว้ หรือ None ซึ่งบ่งบอกถึงการไม่มีค่า ชนิดข้อมูลนี้มาแทนค่า null ที่มีในภาษาอื่นและบังคับให้นักพัฒนาจัดการกรณีที่ไม่มีค่าอย่างชัดเจน จึงหลีกเลี่ยงข้อผิดพลาด null pointer ขณะรันไทม์ ## 2. ชนิดข้อมูลใดของ Rust ที่แสดงถึงการดำเนินการที่อาจสำเร็จหรือล้มเหลวพร้อมข้อผิดพลาด? **คำตอบ** Result เป็น enum ที่มีสองรูปแบบ: Ok(T) สำหรับความสำเร็จซึ่งบรรจุค่าที่ส่งกลับ และ Err(E) สำหรับความล้มเหลวซึ่งบรรจุข้อผิดพลาด ชนิดข้อมูลนี้บังคับให้จัดการข้อผิดพลาดอย่างชัดเจนแทนการใช้ exception ทำให้โค้ดคาดเดาได้มากขึ้นและข้อผิดพลาดมองเห็นได้ชัดขึ้น ## 3. เมธอด unwrap() ทำอะไรกับ Option? **คำตอบ** unwrap() จะคืนค่าที่อยู่ภายใน Some(T) หากมีค่านั้น หาก Option เป็น None โปรแกรมจะ panic (panic!) และหยุดทำงานทันที เมธอดนี้สะดวกสำหรับการสร้างต้นแบบ แต่ควรหลีกเลี่ยงในระบบโปรดักชันเพราะไม่ได้จัดการกรณี None อย่างนุ่มนวล ## มีอีก 15 คำถาม - ความแตกต่างระหว่าง unwrap() และ expect() คืออะไร? - ตัวดำเนินการ ? ทำอะไรในฟังก์ชันที่คืนค่า Result? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Rust อื่นๆ - [พื้นฐาน Rust](https://sharpskill.dev/th/technologies/rust/interview-questions/rust-basics.md): 25 คำถาม, Junior - [Ownership & Borrowing](https://sharpskill.dev/th/technologies/rust/interview-questions/ownership-borrowing.md): 22 คำถาม, Junior - [Structs & Enums](https://sharpskill.dev/th/technologies/rust/interview-questions/structs-enums.md): 20 คำถาม, Junior - [คอลเลกชัน](https://sharpskill.dev/th/technologies/rust/interview-questions/collections.md): 20 คำถาม, Junior - [โมดูลและแพ็กเกจ](https://sharpskill.dev/th/technologies/rust/interview-questions/modules-packages.md): 18 คำถาม, Junior - [Traits](https://sharpskill.dev/th/technologies/rust/interview-questions/traits.md): 22 คำถาม, Mid-Level - [Generics](https://sharpskill.dev/th/technologies/rust/interview-questions/generics.md): 20 คำถาม, Mid-Level - [Lifetimes](https://sharpskill.dev/th/technologies/rust/interview-questions/lifetimes.md): 20 คำถาม, Mid-Level - [Iterators & Closures](https://sharpskill.dev/th/technologies/rust/interview-questions/iterators-closures.md): 22 คำถาม, Mid-Level - [Smart Pointers](https://sharpskill.dev/th/technologies/rust/interview-questions/smart-pointers.md): 22 คำถาม, Mid-Level - [Concurrency Basics](https://sharpskill.dev/th/technologies/rust/interview-questions/concurrency-basics.md): 20 คำถาม, Mid-Level - [async/await](https://sharpskill.dev/th/technologies/rust/interview-questions/async-await.md): 22 คำถาม, Mid-Level - [Testing](https://sharpskill.dev/th/technologies/rust/interview-questions/testing.md): 18 คำถาม, Mid-Level - [Cargo & Ecosystem](https://sharpskill.dev/th/technologies/rust/interview-questions/cargo-ecosystem.md): 18 คำถาม, Mid-Level - [Pattern Matching](https://sharpskill.dev/th/technologies/rust/interview-questions/pattern-matching.md): 18 คำถาม, Mid-Level - [มาโคร](https://sharpskill.dev/th/technologies/rust/interview-questions/macros.md): 20 คำถาม, Mid-Level - [Serde และการ Serialization](https://sharpskill.dev/th/technologies/rust/interview-questions/serde-serialization.md): 20 คำถาม, Mid-Level - [Unsafe Rust](https://sharpskill.dev/th/technologies/rust/interview-questions/unsafe-rust.md): 20 คำถาม, Senior - [Trait ขั้นสูง](https://sharpskill.dev/th/technologies/rust/interview-questions/advanced-traits.md): 22 คำถาม, Senior - [Lifetime ขั้นสูง](https://sharpskill.dev/th/technologies/rust/interview-questions/advanced-lifetimes.md): 20 คำถาม, Senior - [Type System](https://sharpskill.dev/th/technologies/rust/interview-questions/type-system.md): 20 คำถาม, Senior - [Tokio & Async I/O](https://sharpskill.dev/th/technologies/rust/interview-questions/tokio-async.md): 22 คำถาม, Senior - [การเพิ่มประสิทธิภาพ](https://sharpskill.dev/th/technologies/rust/interview-questions/performance-optimization.md): 20 คำถาม, Senior - [Memory Management](https://sharpskill.dev/th/technologies/rust/interview-questions/memory-management.md): 20 คำถาม, Senior - [Web Frameworks](https://sharpskill.dev/th/technologies/rust/interview-questions/web-frameworks.md): 22 คำถาม, Senior - [Database Integration](https://sharpskill.dev/th/technologies/rust/interview-questions/database-integration.md): 20 คำถาม, Senior - [Design Pattern ของ Rust](https://sharpskill.dev/th/technologies/rust/interview-questions/design-patterns.md): 20 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/rust/interview-questions/error-handling