guard
Runs block and throws AppDiedException if any watched app crashed or stopped responding while it ran: from the command that failed because of it (its CommandException is the cause), when the block ends without failing, or in place of the block's own failure (which is then suppressed). Without a death, the block's value or failure comes through unchanged.
try {
device.guard { app.element(text("Pay")).tap(); app.await(text("Paid")).visible() }
} catch (died: AppDiedException) {
println(died.death.stackTrace)
}A death the block threw for is handled (AppDeath.handled): no outer block or end-of-test check reports it again, and it explains no later failure. The client learns of a death at the next Tap call or at the end of the block (up to 300 ms after the latest input, because Android logs a crash shortly after the input that caused it); it cannot stop the block's own code at the moment of the crash.
Inside a JUnit test the end-of-test check already fails a test whose app died; guard moves that failure to the end of the block, for code that goes on after it, or outside a test.