If the error has a "cause" which is another UserException or String, the dialog-title will be the present exception's msg, and the dialog-content will be the cause. Otherwise, the dialog-title will be an empty string, and the dialog-title will be the present exception's msg.
In other words, If the cause is an UserException or String, it may be used in the dialog. But if the cause is of a different type it's considered just internal information, and won't be shown to the user.
An UserException may also have an optional code, of type ExceptionCode. If there is a non-null code, the String returned by ExceptionCode.asText may be used instead of the msg. This facilitates translating error messages, since ExceptionCode.asText accepts a Locale.
You can define a special Matcher for your UserException, to use in your tests. Create a test lib with this code:
import 'package:matcher/matcher.dart'; const Matcher throwsUserException = Throws(const TypeMatcher<UserException>());
Then use it in your tests:
expect(() => someFunction(), throwsUserException);
- Implemented types
- cause → Object
The cause of the user-exception. Usually another error.
- code → ExceptionCode
The error may have some code. This may be used for error message
translations, and also to simplify receiving errors from web-services,
- hashCode → int
The hash code for this object. [...]
- msg → String
Some message shown to the user.
- runtimeType → Type
A representation of the runtime type of the object.