Error class
class Error {
const Error();
/**
* Safely convert a value to a [String] description.
*
* The conversion is guaranteed to not throw, so it won't use the object's
* toString method.
*/
static String safeToString(Object object) {
if (object is int || object is double || object is bool || null == object) {
return object.toString();
}
if (object is String) {
// TODO(ahe): Remove backslash when http://dartbug.com/4995 is fixed.
String string = object;
const backslash = '\\';
String escaped = string
.replaceAll('$backslash', '$backslash$backslash')
.replaceAll('\n', '${backslash}n')
.replaceAll('\r', '${backslash}r')
.replaceAll('"', '$backslash"');
return '"$escaped"';
}
return _objectToString(object);
}
external static String _objectToString(Object object);
}
Subclasses
AbstractClassInstantiationError, ArgumentError, AssertionError, CastError, ConcurrentModificationError, FallThroughError, JsonUnsupportedObjectError, NoSuchMethodError, NullThrownError, OSError, OutOfMemoryError, RuntimeError, StackOverflowError, StateError, UnsupportedError
Static Methods
String safeToString(Object object) #
Safely convert a value to a String description.
The conversion is guaranteed to not throw, so it won't use the object's toString method.
static String safeToString(Object object) {
if (object is int || object is double || object is bool || null == object) {
return object.toString();
}
if (object is String) {
// TODO(ahe): Remove backslash when http://dartbug.com/4995 is fixed.
String string = object;
const backslash = '\\';
String escaped = string
.replaceAll('$backslash', '$backslash$backslash')
.replaceAll('\n', '${backslash}n')
.replaceAll('\r', '${backslash}r')
.replaceAll('"', '$backslash"');
return '"$escaped"';
}
return _objectToString(object);
}
Constructors
const Error() #
const Error();