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.
Do you have questions? We’re always here to help! Join our Facebook group and ask away!
If you are new to programming, make sure to watch the Free Full Java Basics course first, as it is a necessary prerequisite to this one. It explains the topics in a lot more detail, as this video aims to revise them and get to more complex topics after that.
This course is also perfect for people who have some background in programming with a different language and would like to pick up on Java.
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
Remember that coding is a skill, which should be practiced. To learn to code, you should write code, every day, for a long time. Watching tutorials is not enough. You should code! Now it’s your turn. Do your exercises!
Register now and take your free resources right away! You will get access to the 55+ fully automated exercises which will sharpen your coding skills. You will become a member of the SoftUni Global Community and we will provide you the opportunity to communicate with other students and mentors and get help for FREE.