Class ExtensionException

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
GuiceException

public abstract non-sealed class ExtensionException extends ConfigurationException

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: