From the course: Build Spring Boot Apps with the Kotlin Programming Language
Unlock this course with a free trial
Join today to access over 22,600 courses taught by industry experts.
Exceptions are unchecked
From the course: Build Spring Boot Apps with the Kotlin Programming Language
Exceptions are unchecked
- [Instructor] Hello, welcome to Chapter 12. In this chapter, we're going to be looking at exceptions. I should just say before we start, I've switched back to the learning Kotlin project and I've just created a brand new Kotlin file with a main method in. Now that's the only things I've done off camera. Okay, so we know that Kotlin does a lot to help us avoid the dreaded null pointer exception. It's possible to still get one, but we do have to work quite hard to do it. But what about other exception types? Well, first of all our code can, of course, generate exceptions if I did something like this. Let's println(7/0) and run that. We'll see we get a java.lang.ArithmeticException / by zero. So exceptions can occur just like they do in java and we can try and catch those exceptions. So for example, I could surround this in a try-catch block and let's catch an arithmetic exception. So the format, of course, is going to be the variable name. Let's call it e: variable type, which is…
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.