A try clause can support multiple catch blocks, each designed to handle a particular type of exception. To design these, you need to understand the inheritance hierarchy of exceptions. The top of the hierarchy is the Exception class—all other exception objects are derived from that class.
- [Instructor] When you use structured…exception handling in Java,…you're looking for particular kinds of exceptions.…In this code that I demonstrated in the previous video,…I have two bits of code that might generate an exception.…The first bit of code is correct right now,…it extracts a value out of an array…using an index of cars dot length minus one.…Because of the zero-based offset,…that means give me the last item in the array.…If I change that, so I'm looking for just the length,…that generates an array index out of bounds exception.…
If I fix that expression, my flow can now…get to this bit of code that tries to…call a method from a null object.…And that generates a null pointer exception.…Right now though, I only have a catch block…for the array index out of bounds exception.…To fix that, you can add multiple catch sections.…I'll start by typing the keyword catch,…then inside the parenthesis, I'll pass in…the type of the exception I'm looking for,…null pointer exception.…I'll give that object an identifier of E,…
- Debugging Java code
- Handling exceptions
- Creating custom classes
- Working with inheritance
- Managing data collections
- Using Java packages and libraries
- Preparing a Java application for deployment
Skill Level Intermediate
1. Exception Handling and Debugging
2. Create Custom Classes
3. Work with Inheritance
4. Manage Data Collections
5. Use Java Packages and Libraries
Work with dates and times7m 12s
6. Prepare a Java Application for Deployment
Next steps1m 12s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.