From the course: Rust Programming: From Fundamentals to Advanced Concepts with AI-Assisted Development
Unlock this course with a free trial
Join today to access over 25,600 courses taught by industry experts.
Demo: Using panic to stop a program - Rust Tutorial
From the course: Rust Programming: From Fundamentals to Advanced Concepts with AI-Assisted Development
Demo: Using panic to stop a program
- [Instructor] In languages like JavaScript, you have a throw where you can throw errors, throw exceptions. And in Python you can raise these exceptions. In languages like Golang and Rust, you have the ability to call a panic. A panic is something that will immediately halt execution of a program with an error message and it will cause the program to exit early with an optional back trace. So we can actually say right here at the very top and we can say error. We are panicking or we're crashing the program. That's fine. So now you can see that immediately the text agent knows that this is not going to get executed. So if I run this yes unreachable statement right here, any code following this expression is unreachable. Yes, we're having a panic and you can see here threat main panic.error we're crashing the program. Perfect. So that's good. Well, that's not entirely good. We're going to remove these and in this case we are going to be calling loop and panic and we're going to run that…
Contents
-
-
-
-
-
-
-
-
(Locked)
Introduction to function basics1m 11s
-
(Locked)
Demo: Simple unit functions1m 46s
-
(Locked)
Demo: Return values5m 50s
-
(Locked)
Demo: Using arguments3m 36s
-
(Locked)
Demo: The borrowing concept10m 9s
-
(Locked)
Demo: Using panic to stop a program4m
-
(Locked)
Demo: Basic error handling with match6m 55s
-
(Locked)
Summary of function basics1m 23s
-
(Locked)
-
-
-
-
-
-
-