| Index: lib/src/utils.dart
|
| diff --git a/lib/src/utils.dart b/lib/src/utils.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4dcee1988000e1a0d77be60a35765881625bd753
|
| --- /dev/null
|
| +++ b/lib/src/utils.dart
|
| @@ -0,0 +1,23 @@
|
| +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +import 'package:source_span/source_span.dart';
|
| +
|
| +/// Runs [body] and wraps any format exceptions it produces.
|
| +///
|
| +/// [name] should describe the type of thing being parsed, and [value] should be
|
| +/// its actual value.
|
| +wrapFormatException(String name, String value, body()) {
|
| + try {
|
| + return body();
|
| + } on SourceSpanFormatException catch (error) {
|
| + throw new SourceSpanFormatException(
|
| + 'Invalid $name: ${error.message}', error.span, error.source);
|
| + } on FormatException catch (error) {
|
| + throw new FormatException(
|
| + 'Invalid $name "$value": ${error.message}',
|
| + error.source,
|
| + error.offset);
|
| + }
|
| +}
|
|
|