Class ExtensionException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
GuiceException
A sub exception of ConfigurationException that can be implemented by users of the library for throwing
own exceptions during the initialization of Extensions or in PropertyProviderSkeleton.supplier().
This class comes particularly handy, because it allows to easily use exception messages defined via
fluent localization files in your resource folder, avoiding long strings in your source code and enabling
accessing all the comfortable features of the Fluava library.
To use this class, you have to first create an own class extending this one:
public class MyException extends ExtensionException {
...
}
To state the bundle name from which your messages should be loaded, you have to pass an instance of
ExtensionException.Information to all the constructors you need:
public class MyException extends ExtensionException {
private static final Information INFO = new Information("extension_errors")
public MyException(String key) {
super(INFO, key);
}
public MyException(String key, Entry... placeholder) {
super(INFO, key, placeholder);
}
...
}
Now, let's assume you have the following bundle in your resource folder:
_extension_errors_en.ftl
first-error = This is the first error with msg: { $msg }
To create an exception with first-error as your message, just call the constructor with
the key first-error and your placeholder set:
new MyException("first-error", Entry.entry("msg", "Exception in...")).
Throwable.getMessage() will now be set to:
This is the first error with msg: Exception in...
Please note here, that all messages will be resolved for Locale.ENGLISH, thus you have to provide
resource files for your bundle name and the english locale (they have to end on _en.ftl like the example above).
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe information object holding information like theBundlename to use. -
Field Summary
Fields inherited from class JDACException
bundle, errorMessages -
Constructor Summary
ConstructorsConstructorDescriptionExtensionException(ExtensionException.Information information, String key) ExtensionException(ExtensionException.Information information, String key, Entry... placeholder) ExtensionException(ExtensionException.Information information, String key, Throwable cause) ExtensionException(ExtensionException.Information information, String key, Throwable cause, Entry... placeholder) -
Method Summary
Methods inherited from class ConfigurationException
getMessageMethods inherited from class JDACException
errorMessage, errorMessageMethods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
ExtensionException
- Parameters:
information- theExtensionException.Informationobject holding all necessary (static) information to resolve the messageskey- the bundle key of the error message
-
ExtensionException
public ExtensionException(ExtensionException.Information information, String key, Entry... placeholder) - Parameters:
information- theExtensionException.Informationobject holding all necessary (static) information to resolve the messageskey- the bundle key of the error messageplaceholder- the placeholders to insert
-
ExtensionException
- Parameters:
information- theExtensionException.Informationobject holding all necessary (static) information to resolve the messageskey- the bundle key of the error messagecause- the cause of the exception
-
ExtensionException
public ExtensionException(ExtensionException.Information information, String key, Throwable cause, Entry... placeholder) - Parameters:
information- theExtensionException.Informationobject holding all necessary (static) information to resolve the messageskey- the bundle key of the error messagecause- the cause of the exceptionplaceholder- the placeholders to insert
-
-
Method Details
-
information
- Returns:
- the stored
ExtensionException.Informationobject
-
bundle
public dev.goldmensch.fluava.Bundle bundle()- Returns:
- the underlying
Bundle, which is used to resolve the requested messages
-