Panic support macros and functions
Structs
Functions
-
Catch a panic and return it as a result.
This function will execute the provided closure and return
Result::ok
if the closure completes successfully, orResult::err
if the closure panics.This is primarily meant to support unit tests that need to verify that a certain function panics under certain conditions.
catch_panic
only affects the panics occurring on the calling thread.Example
use std::panicking::catch_panic; let result = catch_panic(|| { panic!("test panic"); }); assert!(result.is_err());
Run this exampleIt is not recommended to use this function for general error handling, as Alumina panics do not unwind the stack, which means that any resources that need to be cleaned up will not be cleaned up.
See also assert_panics for a more convenient way to test for panics.
use std::panicking::catch_panic; use std::collections::Vector; let result = catch_panic(|| { let vec = Vector::from_slice(&[1, 2, 3, 4, 5]); // will never be freed defer vec.free(); panic!("test panic"); }); assert!(result.is_err());
Run this example
Macros
Ungracefully terminate the thread or process with an error message.