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.
Lesson Topics
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
Practical Exercises
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:
2 thoughts on “[11/13] Java Foundations Certification: Exception Handling”
java code for
sin(180 )=?
//180 in degree
Hello,
You can use the following code to calculate sin(180):
double angle = 180;
double sin180 = Math.sin(Math.toRadians(angle));
System.out.println(Math.round(sin180));
Notice we use Math.round() at the end. Otherwise, you will get a number very close to 0, but not exactly zero.
We hope that was helpful. We’re available for any questions to follow.
Have a great day!