UserException class

Represents an error the user could fix, like wrong typed text, or missing internet connection. Methods dialogTitle and dialogContent return Strings you can show in an error dialog.

An UserException may have an optional cause, which is a more specific root cause of the error.

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

Constructors

UserException(String msg, {Object cause, ExceptionCode code})
const

Properties

cause Object
The cause of the user-exception. Usually another error.
final
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, cloud-functions etc.
final
hashCode int
The hash code for this object. [...]
read-only, override
msg String
Some message shown to the user.
final
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

dialogContent([Locale locale]) String
dialogTitle([Locale locale]) String
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() String
Returns a string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator. [...]
override

Static Properties

joinExceptionMainAndCause String Function(Locale locale, String mainMsg, String causeMsg)
Return the string that join the main message and the reason message. You can change this variable to inject another way to join them.
read / write