Class ErrorHandler
- All Implemented Interfaces:
EventEmitterInterface
This class provides methods to handle various types of J3DErrors,
categorising them by their severity (mild, warning, fatal) and performing
appropriate actions such as logging, displaying user messages, or
terminating the application. It also supports temporarily ignoring
specific error types.
- Author:
- Lehlogonolo Poole
- See Also:
-
Field Summary
FieldsFields inherited from class EventEmitter
registered -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidemitThenThrow(J3DError err) Broadcasts anEventType.EMITTED_ERRORevent to registered listeners before re-throwing the error.booleanHandles a givenJ3DError, processing it based on its type and severity.voidhandleThenThrow(J3DError err) Handles a givenJ3DErrorusing thehandle(J3DError)method and then re-throws it.<T extends J3DError>
voidRegisters a specificJ3DErrorclass to be ignored by the error handler.Methods inherited from class CapableEventEmitter
capableBroadcastMethods inherited from class EventEmitter
attachListener, broadcast, detachAll, detachListener, genericAttach, genericBroadcast, genericDetach, genericDetachAll, isAttached
-
Field Details
-
ignored
-
-
Constructor Details
-
ErrorHandler
public ErrorHandler()
-
-
Method Details
-
ignore
Registers a specificJ3DErrorclass to be ignored by the error handler. When an error of the registered class type is encountered by thehandle(J3DError)method, it will be consumed (removed from the ignore list) and no further action will be taken. This effectively makes the next occurrence of that specific error type to be silently handled.- Type Parameters:
T- The type ofJ3DErrorto ignore.- Parameters:
err- TheClassobject of theJ3DErrorto be ignored.- Throws:
RuntimeException- if more than 10 error classes are attempted to be ignored.
-
handle
Handles a givenJ3DError, processing it based on its type and severity.If the error is registered to be ignored, that is handled
Otherwise, the error is processed based on its specific type:
J3DMild: The error is printed to the application's log.J3DWarning: The error is printed to the application's log, and a warning message dialogue is displayed to the user.J3DFatal: The error is printed to the application's log, and a fatal error message dialogue is displayed to the user. If the fatal error'sterminate()method returns true, an additional message is shown, and the application is terminated viaSystem.exit(1).- Any other
J3DErrortype (that is also an instance ofJ3ErrSeverity): The error is simply printed to the application's log.
- Parameters:
err- TheJ3DErrorinstance to be handled.
-
handleThenThrow
Handles a givenJ3DErrorusing thehandle(J3DError)method and then re-throws it.- Parameters:
err- TheJ3DErrorinstance to be handled and thrown.- Throws:
J3DError- The sameJ3DErrorinstance that was passed in, after it has been processed by thehandle(J3DError)method.
-
emitThenThrow
Broadcasts anEventType.EMITTED_ERRORevent to registered listeners before re-throwing the error.Unlike
handleThenThrow(J3DError), this method usesCapableEventEmitterto query registeredCapableEventListenerinstances viaCapableEventEmitter.capableBroadcast(EventType, EventPayload).This allows listeners to intercept the error and return a
Booleanresponse indicating whether standard handling should be suppressed or executed:- If no
CapableEventListeneris present to intercept the event, it falls back tohandleThenThrow(J3DError). - If a listener intercepts the event, its boolean result dictates subsequent handling before throwing.
trueresult, the error is considered handled and is never thrown - If no
-