Handling Errors: Handling Exceptions in Java
Java
| Beginner
- 8 videos | 1h 9m 40s
- Includes Assessment
- Earns a Badge
It is important to handle exceptions proactively in Java to ensure that the flow of a program doesn't break on the occurrence of an exception. Take this course to explore the fundamentals of handling exceptions and different constructs available in Java that allow you to do so. Delve into working with try-catch, finally, and try-with-resource blocks to handle various exceptions within your code. These blocks can be used to catch single, multiple, or categories of exceptions, clean up after your code has run, and handle exceptions related to specific Java objects, respectively. Upon completion of this course, you'll be able to implement exception handling within Java effectively.
WHAT YOU WILL LEARN
-
Discover the key concepts covered in this courseRecognize how the throwing of exceptions influences the flow of a java programImplement a basic try-catch block to handle an exception in javaUse multiple catch blocks to handle different types of exceptions in your code
-
Use a finally block to clean up after code execution in a try-catchUse the throws keyword in a method signature instead of implementing an exception handlerImplement a try-with-resource block to close resources after their useSummarize the key concepts covered in this course
IN THIS COURSE
-
2m 18sIn this video, you’ll learn more about your instructor and this course. In this course, you’ll learn the fundamentals of exception handling and the different constructs available in Java to achieve this end. You’ll implement a try-catch block and learn how try-catch blocks can be used to catch single, multiple, and categories of exceptions. You’ll use finally blocks to clean up after your code has run. Finally, you’ll implement a try with resource block. FREE ACCESS
-
8m 31sIn this video, you’ll watch a demo. You’ll explore exception handling and learn the flow of a program when an exception is thrown. Onscreen, you’ll see a new source file called HandlingExceptions.java has been within the project. You’ll now paste in some code. You’ll see there’s an array of double values onscreen. The variable called index has been initialized. There are also three different print statements included. FREE ACCESS
-
9m 49sIn this video, you’ll watch a demo. You’ll take a deeper look at the exception object. First, you’ll clear the console. Then, you’ll introduce a new try catch block. Inside the try block you have the same line as before with the invocation of System.out.format which will throw an exception. In the catch block you’ll explore different methods available for an exception object. FREE ACCESS
-
12m 47sIn this video, you’ll watch a demo. You’ll explore how it’s possible to define multiple handlers by creating several catch blocks for each try block. You’ll see a new MultipleExceptions class has been created. You’ll see there are two types of exceptions that can be thrown. First, thought, you’ll take a look at what the code contains. You’ll see you have a starting print statement at the top. FREE ACCESS
-
12m 52sIn this video, you’ll watch a demo. You’ll learn to work with the finally block. This is something included at the end of a try-catch block. It’s executed whether or not an exception is thrown. Onscreen, you’ll see a new class called FinallyBlock has been created within a new source file here. One common use case of the FinallyBlock is to close out any resources that have been consumed during the code execution. FREE ACCESS
-
10m 58sIn this video, you’ll watch a demo. You’ll explore other cases of the throws keyword and see how it can be applied when you have recursive function calls. You’ll see a new source file has been created. It’s a new class called ThrowsKeyword. You’ll begin by adding in some code. This code will be similar to what you’ve already worked with. You’ll import a BufferedReader, File, and FileReader to read from a file. FREE ACCESS
-
10m 23sIn this video, you’ll watch a demo. In this demo, you’ll learn how the closing of a resource after it has been used can be made more concise using a TryWithResourcesBlock. If you have a background in Python programming, you’ll see this is Java's equivalent of the width block. You’ll see a new source file has been created, as well as a class called TryWithResourcesBlock. FREE ACCESS
-
2m 3sIn this video, you’ll summarize what you’ve learned in this course. You’ve learned to implement a try-catch block. You also covered how try-catch blocks can be used to catch single, multiple, or categories of exceptions. You also learned the hierarchy of exception classes in Java and how this can be used to define your own exception handlers. You also used finally blocks to clean up after your code has run, whether an exception was thrown. FREE ACCESS
EARN A DIGITAL BADGE WHEN YOU COMPLETE THIS COURSE
Skillsoft is providing you the opportunity to earn a digital badge upon successful completion on some of our courses, which can be shared on any social network or business platform.
Digital badges are yours to keep, forever.