rustHow to throw custom error in Rust
Rust provides the panic! macro to throw custom errors. It takes a &str argument which is the error message.
Example code
fn main() {
panic!("Custom error message");
}
Output example
thread 'main' panicked at 'Custom error message', src/main.rs:2:5
The code consists of:
panic!macro: used to throw a custom error&strargument: the error message
Helpful links
More of Rust
- How to use Unicode in a regex in Rust?
- How to match a URL with a regex in Rust?
- Pointer comparison in Rust
- How to match whitespace with a regex in Rust?
- How to replace a capture group using Rust regex?
- How to replace strings using Rust regex?
- How to convert a Rust slice to a fixed array?
- How to use 'or' in Rust regex?
- How do I get the last character from a string in Rust?
- How borrow instead of move in Rust
See more codes...