![]() The previously described examples for additional attributes or methods showed the intention of a custom exception. That quickly pays off if multiple developers work on the same application or library, new team members join your project, or a third-party software vendor decides to use your APIs. They also reduce the required amount of documentation. These recommendations make your code and API easier to understand. There are 4 general best practices that you should follow when you decide to implement a custom exception class. These can store additional information, like an application-specific error code, or provide utility methods that can be used to handle or present the exception to a user. You can take this concept one step further by using a custom exception.Ĭustom exceptions provide you the flexibility to add attributes and methods that are not part of a standard Java exception. The Java Exception class describes the kind of event, and the message provides detailed information about it. You often can achieve that by using standard exceptions with good messages. You should provide detailed information about the situation that caused the exception, and you should not remove anything that might be useful to the caller. If you’ve read these posts, you probably recognized a pattern. We already talked a lot about exception handling on this blog and described the differences between checked and unchecked exceptions, best practices and common mistakes. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |