We have introduced exceptions briefly in Chapter 1, Getting Started with Java 12. In this chapter, we will treat this topic more systematically. There are two kinds of exceptions in Java: checked and unchecked exceptions. Both of them will be demonstrated and the difference between the two will be explained. The reader will also learn about the syntax of the Java constructs related to exceptions handling and the best practices to address (handle) the exceptions. The chapter will end with the related topic of an assertion statement that can be used to debug the code in production.
The following topics will be covered in this chapter:
- Java exceptions framework
- Checked and unchecked (runtime) exceptions
- The try, catch, and finally blocks
- The throws statement
- The throw statement
- The assert statement
- Best practices of exceptions handling