MessageSourceException class
An exception that occurs when resolving messages from a MessageSource.
This exception provides additional context beyond a simple error message:
- code: the message key that failed to resolve.
- locale: the locale that was requested when the error occurred.
- resource: the underlying resource (e.g., file, bundle, or database) involved.
cause
: the original exception that triggered this error, if any.
This is especially useful in internationalization (i18n) and configuration systems where message lookup may fail due to missing keys, unsupported locales, or inaccessible resources.
Example
void loadMessage(String key, Locale locale) {
throw MessageSourceException(
"Message key not found",
code: key,
locale: locale,
resource: "messages_en.properties",
);
}
try {
loadMessage("missing.key", Locale("en"));
} catch (e) {
print(e);
// Output:
// MessageSourceException: Message key not found [code=missing.key] [locale=en] [resource=messages_en.properties]
}
Constructors
- MessageSourceException(String message, {String? code, Locale? locale, String? resource, Object? cause})
- An exception that occurs when resolving messages from a MessageSource.
Properties
- cause → Object?
-
The underlying cause of this exception, if any.
finalinherited
- code → String?
-
The message code (key) that failed to resolve.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- locale → Locale?
-
The locale in which the message was being resolved.
final
- message → String
-
The message describing the error.
finalinherited
- resource → String?
-
The resource (e.g., properties file, database, etc.)
that was queried during resolution.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stackTrace → StackTrace
-
The associated stack trace.
finalinherited
Methods
-
getCause(
) → Object -
The cause of this exception, if any.
inherited
-
getMessage(
) → String -
The message associated with this exception.
inherited
-
getStackTrace(
) → StackTrace -
The stack trace associated with this exception.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String - A string representation of this object.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited