From the course: Grasshopper and Rhino: C# Scripting
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Try and catch
- [Narrator] The last thing we're going to learn about the C# programming language in this section is the try and catch statement. When something goes wrong in our script, like an error occurs, an exception is thrown. This means our script can't execute anymore due to this error. And the error message is relayed back to the user. So in this lesson, we'll learn how to account for these errors, and handle them safely. In a new Grasshopper file, let's go ahead and place a new C# component, and open it up. To start, let's see what happens when we cause an error on purpose. Go ahead and create a new list of type int, which we'll call test, and we'll initialize it as an empty list. Now on the next line, let's change the item at index three to the number 99. As you might be able to guess, this statement will cause an error because there are no items in the list, and therefore we cannot change the item at index three.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Commenting2m 27s
-
Variables5m 1s
-
Numbers6m 36s
-
Strings5m 37s
-
Collections5m 34s
-
Arrays5m 32s
-
Comparing with operators5m 3s
-
Conditionals3m 30s
-
Logical operators6m 26s
-
Looping with the for loop5m 23s
-
Foreach looping4m 29s
-
Nested loops5m 12s
-
Methods6m 5s
-
Reference vs. value types5m 21s
-
Try and catch4m 14s
-
-
-