Add SpanException and SpanFormatException classes to source_maps.

It's often useful to associate source range information with an
exception in a way that will get printed along with that exception but
can be pulled out and manipulated directly. It's especially useful if
there's a common superclass/interface for doing so that can be shared
across packages. This adds that superclass.

R=sigmund@google.com

Review URL: https://codereview.chromium.org//348493004

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/source_maps@37509 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e278458..3730a10 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.9.2
+
+* Add `SpanException` and `SpanFormatException` classes.
+
 ## 0.9.1
 
 * Support unmapped areas in source maps.
diff --git a/lib/span.dart b/lib/span.dart
index f47e08e..cc48f19 100644
--- a/lib/span.dart
+++ b/lib/span.dart
@@ -360,3 +360,27 @@
   String getText(int start, [int end]) =>
     super.getText(start - _baseOffset, end == null ? null : end - _baseOffset);
 }
+
+/// A class for exceptions that have source span information attached.
+class SpanException implements Exception {
+  /// A message describing the exception.
+  final String message;
+
+  /// The span associated with this exception.
+  ///
+  /// This may be `null` if the source location can't be determined.
+  final Span span;
+
+  SpanException(this.message, this.span);
+
+  String toString({bool useColors: false, String color}) {
+    if (span == null) return message;
+    return span.getLocationMessage(message, useColors: useColors, color: color);
+  }
+}
+
+/// A [SpanException] that's also a [FormatException].
+class SpanFormatException extends SpanException implements FormatException {
+  SpanFormatException(String message, Span span)
+      : super(message, span);
+}
diff --git a/pubspec.yaml b/pubspec.yaml
index 3c946e0..213587c 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
 name: source_maps
-version: 0.9.1
+version: 0.9.2
 author: Dart Team <misc@dartlang.org>
 description: Library to programmatically manipulate source map files.
 homepage: http://www.dartlang.org