In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "what are the new features of Java7 exception handling". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
In a program, errors may occur in a variety of situations that the programmer did not expect, or environmental factors beyond the programmer's control, such as bad data of the user, trying to open a file that does not exist, and so on. In java, some of the errors that may occur while the program is running are called exceptions. An exception is an event that occurs during the execution of a program, which interrupts the normal instruction stream of the program being executed.
Catch exception
Multiple exception traps are provided in java7
Try {} catch (IndexOutOfBoundsException | NumberFormatException e) {System.out.println ("Array out of bounds...");} custom exception
Most of the exceptions that occur during programming can be described using java's built-in exception classes. In addition, users can customize exceptions according to their business.
Using custom exception classes in a program can be divided into the following steps:
1. Create a custom exception class
2. Throw an exception object through the throw keyword in the method
3. If you handle an exception in the current method that throws an exception, you can use the try-catch statement block to catch and handle the exception. Otherwise, you can use the throws keyword at the method declaration to indicate that the exception is to be thrown to the method caller and handle the exception.
Java7 automatically shuts down resources
Java7 enhances the try statement by allowing the try keyword to be followed by a pair of parentheses, which can declare and initialize one or more resources that will be automatically closed at the end of the try statement.
Exception inheritance system
Exceptions are classified as exceptions (Exception) and errors (Error), both of which are inherited from the Throwable parent class.
That's all for "what are the new features of Java7 exception handling". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.