Rust - Unrecoverable Errors Last Updated : 06 Jun, 2021 Comments Improve Suggest changes Like Article Like Report Unrecoverable errors are those errors which as the name suggests can not be handled by a programmer. When any unrecoverable error occurs the end result is the program quits (terminates). The complete process is the first panic! macro is fired then the error message is printed along with the location of it and finally, the program is terminated. It mostly arises due to the bugs left by the programmer in the code. Example 1: In this example, we will call panic! macro.It will show our error message and the complete stack trace(location, message).After this, it unwinds and cleans up the stack, and then quit(terminate the program). The below program is for unrecoverable error in Rust. Rust // Rust program for unrecoverable error fn main() { // this will result in unrecoverable error panic!("gfg called panic macro"); } Output : thread 'main' panicked at 'gfg called panic macro', src\main.rs:4:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace error: process didn't exit successfully: `target\debug\unrecoverableErrors.exe` (exit code: 101) Example 2 : In this program, we will define one gfg array which will consist of four strings.Now we will try to print 5 element in the array and because the length is 4 [0-3] and we are looking for 5th index than it will trigger panic! macro.After this, it will print the error message, location, and stack trace. The below program is for unrecoverable error in Rust. Rust // Rust program for unrecoverable error fn main() { let gfg=["cp","algo","ds","FAANG"]; // index 5 does not exist // than it will trigger panic! macro println!("{}", gfg[5]); } Output : error: this operation will panic at runtime --> src\main.rs:5:20 | 5 | println!("{}", gfg[5]); | ^^^^^^ index out of bounds: the length is 4 but the index is 5 | = note: `#[deny(unconditional_panic)]` on by default Comment More infoAdvertise with us R rajatagrawal5 Follow Improve Article Tags : Rust Rust exceptions Similar Reads Rust - Recoverable Errors An error is basically an unexpected behavior or event that may lead a program to produce undesired output or terminate abruptly. Errors are things that no one wants in their program. Recoverable errors are those that do not cause the program to terminate abruptly. Example- When we try to fetch a fil 4 min read Variables in Rust Variables are memory addresses used to store information to be referenced and manipulated in programs. They also provide a way of defining data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that 4 min read Rust - Iterator Trait Rust is a systems programming language focusing on speed, concurrency, and ensuring safe code. The iterator trait in Rust is used to iterate over Rust collections like arrays. Syntax: //pub refers to the trait being declared public pub trait Iterator { // type refers to the elements type over which 3 min read Rust - Hello World Program Every programmer starts their programming journey with a simple "Hello World!" program. In this article, we will write our first "Hello World!" Rust program. If you have not yet installed Rust on your system, please go through the link and install it. In this article we will be working on the follow 3 min read Rust Use Declaration In Rust, we have a concept of the 'use' keyword. This keyword is used for importing or at times renaming items from other different modules or crates. Use the keyword to find its usage when we are required to import items or rename items from crates or modules in Rust programs. For precisely calling 4 min read Rust - Multiple Error Types In Rust, sometimes we have scenarios where there is more than one error type. In Rust, the way of handling errors is different compared to other Object Oriented / System languages. Rust specifically uses 'Result' for returning something. The Result <T, E> is basically an enum that has - Ok(T) 3 min read Like