Errors and Panics
Rust has no exceptions: recoverable failures are Result values and bugs are panics. Interviewers test the ? operator, custom error types, library vs application errors and panics.
on this pageshowhide
explore
- Option and Result5 questions
- The Question Mark Operator5 questions
- Custom Failure Types6 questions
- Library vs Application Failures5 questions
- Unwinding and Aborting6 questions
- Context and Backtraces5 questions
questions
page 2 of 2In Rust, what does Option::transpose do to an Option<Result<T, E>>, and why does it suit an optional field that must parse?
level: middleimportance: nice to knowfreq 30%
basics
~10 sOption::transpose turns Option<Result<T, E>> into Result<Option<T>, E>: Some(Ok(v)) becomes Ok(Some(v)), Some(Err(e)) becomes Err(e), and None becomes Ok(None). An absent optional field stays a success while a malformed one is an error.
In Rust, what happens when a Drop implementation panics while the thread is already unwinding from an earlier panic?
level: seniorimportance: nice to knowfreq 20%
basics
~20 sThe process aborts. A destructor panicking during unwinding would need a second unwind mid-cleanup, so the runtime prints 'panic in a destructor during cleanup' and aborts, past any catch_unwind. A Drop panic outside unwinding is an ordinary, catchable panic.
showing 31–32 of 32