Package io.github.astrapi69.design.pattern.observer.exception
package io.github.astrapi69.design.pattern.observer.exception
Provides classes and interfaces for handling exceptions using the observer design pattern
This package is designed to facilitate the management and communication of exceptions within an application By using the observer pattern, it allows multiple components to listen for and respond to exception events, enabling a decoupled and flexible approach to exception handling.
The key interfaces and classes in this package include:
ExceptionEvent
- Encapsulates an exception event, carrying information about an exception that has occurredExceptionListener
- Represents a listener that reacts to exception events, allowing components to respond when exceptions occurExceptionMessage
- Represents a structured message related to an exception, containing details such as a properties key, value, and additional dataExceptionObservers
- Manages a collection of exception listeners and notifies them when an exception event occurs, following the singleton patternExceptionMessages
- Manages a collection of exception messages organized by keys, providing methods to add, retrieve, and remove messages
This package is crucial for implementing a centralized and consistent approach to exception handling in an application It demonstrates how the observer pattern can be applied to ensure that exceptions are effectively communicated and managed across different components in the system.
-
ClassDescriptionThe class
ExceptionEvent
represents an event that encapsulates aThrowable
object It acts as an observable event that can be passed to listeners interested in handling exceptionsThe listener interface for receiving exception events The class that is interested in processing an exception event implements this interface, and the object created with that class is registered with a component using the component'saddExceptionListener
method When the exception event occurs, that object's appropriate method is invokedThe classExceptionMessage
represents a message object used in exception handling It encapsulates information such as a properties key and value, an ID, and additional data that may be related to the exceptionThe classExceptionMessages
manages a collection of exception messages organized by keys It allows adding, retrieving, and removing exception messages based on specific keysThe classExceptionObservers
is a singleton that manages a list ofExceptionListener
objects It allows classes to register and unregister for exception events, and notifies registered listeners when an exception event occurs