ADVERTISEMENT
ADVERTISEMENT

Rust program to demonstrate the panic!() macro

Rust Example: Write a program to demonstrate the panic!() macro.
Submitted by Nidhi, on November 25, 2021

Problem Solution:

In this program, we will demonstrate panic!() macro. The panic!() macro terminates the program immediately and provides feedback.

Program/Source Code:

The source code to demonstrate the panic!() macro is given below. The given program is compiled and executed successfully.

// Rust program to demonstrate 
// the panic!() macro

fn main() {
   panic!("Error Occurred");
   println!("End of the program"); 
}

Output:

thread 'main' panicked at 'Error Occurred', main.rs:5:4
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Explanation:

In the main() function, we called panic!() macro with the message "Error Occurred". That's why the program gets terminated immediately by calling println!() macro. The panic!() macro terminates the program immediately and provides feedback.

Rust Miscellaneous Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.