Error Handling
Stof throw & try-catch
#[main]
fn main() {
try throw();
catch {
/* recover from an error */
}
}Throw
#[main]
fn main() {
try {
throw("CustomError");
} catch (error: str) { // will try casting the error to a str if needed
switch (error) {
case "CustomError": {
pln("handling the custom error");
}
default: {
pln("optional handling of an unknown error");
}
}
}
}Last updated