skip to content

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 pageshow

explore

questions

page 2 of 2

In 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 s

Option::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.

open as a page

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 s

The 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.

open as a page

showing 31–32 of 32