From the course: Learning Groovy
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Exception handling
- [Instructor] Things can go wrong during the execution of code. Java and groovy use the concept of exceptions to indicate an error condition. The original intent of exceptions is defined as follows. Checked exceptions represent error conditions that a program can recover from and that need to be handled. Unchecked exceptions indicate a failure condition that we can recover from. Handling exceptions in groovy works exactly the same way as in Java. You can write a try block that catches an exception and a catch block that handles the exception. There's one major difference between groovy and Java though. In groovy, exception handling is optional. That means you can decide to handle it or not, even if the exception type is a checked exception. We'll enhance our example code by trying it to convert a string into a long. So here we are going to get the first name. And then we'll turn it into a long and see what happens.…
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
-
-
-
-
Groovy and Java3m 21s
-
(Locked)
Variables and data types2m 54s
-
Classes and methods2m 46s
-
(Locked)
Conditional structures and loops2m 51s
-
(Locked)
Exception handling2m 35s
-
(Locked)
Using the GDK documentation2m 25s
-
(Locked)
Challenge: Creating and using a class1m 37s
-
(Locked)
Solution: Creating and using a class7m 10s
-
-
-