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&str
argument: the error message
Helpful links
More of Rust
- How to replace a capture group using Rust regex?
- Regex example to match multiline string in Rust?
- How to parse a file with Rust regex?
- How to use regex lookahead in Rust?
- How to use regex captures in Rust?
- How to use regex to match a group in Rust?
- How to match the end of a line in a Rust regex?
- How to perform matrix operations in Rust?
- How to use regex to match a double quote in Rust?
- How to replace strings using Rust regex?
See more codes...