In the current lesson, we take a close look at exception handling and why it’s important in software engineering.
What are exceptions? We’ve all seen one, there is no way to write completely bug-free code. In short an exception is a problem that arises during the execution of the program.
Exceptions simplify code construction and maintenance and allow problematic situations to be processed at multiple levels.
In Java exceptions are objects. The base for all exceptions is the Throwable class – it contains information about the cause of the exception, its description, and the stack trace.
There are two types of exceptions – checked (also known as compile-time exceptions), and unchecked (also known as runtime exceptions).
Exceptions can be handled by the try-catch construction. The try-finally block is also used, especially when we want to ensure the execution of a given block of code.
To raise an exception, we use the throw keyword. When an exception is thrown the program execution stops, and the execution travels over the stack until a matching catch block is reached to handle it.
In this lesson you will find many helpful examples and exercises, so make sure to practice what you’ve learned! That’s the only way to grasp the concept at hand.
1. What are Exceptions?
- The Exception class
- Types of exceptions and their hierarchy
2. Handling Exceptions
3. Raising (throwing) Exceptions
4. Best Practices
5. Creating Custom Exceptions
Watch the video and solve the problems. To better understand the material, do the coding exercises and implement the knowledge you acquired. Writing code is the only way to master the skill of code.
Submit your code in the SoftUni Judge System: