Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: lib/core/future.dart

Issue 11225017: Improvement on future: add stack trace to future failures. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | lib/coreimpl/future_implementation.dart » ('j') | tests/corelib/future_test.dart » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * A [Future] is used to obtain a value sometime in the future. Receivers of a 6 * A [Future] is used to obtain a value sometime in the future. Receivers of a
7 * [Future] can obtain the value by passing a callback to [then]. For example: 7 * [Future] can obtain the value by passing a callback to [then]. For example:
8 * 8 *
9 * Future<int> future = getFutureFromSomewhere(); 9 * Future<int> future = getFutureFromSomewhere();
10 * future.then((value) { 10 * future.then((value) {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 186
187 /** 187 /**
188 * Thrown if a completer tries to set the value on a future that is already 188 * Thrown if a completer tries to set the value on a future that is already
189 * complete. 189 * complete.
190 */ 190 */
191 class FutureAlreadyCompleteException implements Exception { 191 class FutureAlreadyCompleteException implements Exception {
192 FutureAlreadyCompleteException() {} 192 FutureAlreadyCompleteException() {}
193 String toString() => "Exception: future already completed"; 193 String toString() => "Exception: future already completed";
194 } 194 }
195 195
196 /**
197 * Wraps unhandled exceptions provided to [Completer.completeException]. It is
198 * used to show both the error message and the stack trace for unhandled
199 * exceptions.
200 */
201 class FutureUnhandledException implements Exception {
202 /** Wrapped exception. */
203 var source;
204
205 /** Trace for the wrapped exception. */
206 Object stackTrace;
207
208 FutureUnhandledException(this.source, this.stackTrace);
209
210 String toString() {
211 return 'FutureUnhandledException: exception while executing Future\n '
212 '${source.toString().replaceAll("\n", "\n ")}\n'
213 'original stack trace:\n '
214 '${stackTrace.toString().replaceAll("\n","\n ")}';
215 }
216 }
217
196 218
197 /** 219 /**
198 * [Futures] holds additional utility functions that operate on [Future]s (for 220 * [Futures] holds additional utility functions that operate on [Future]s (for
199 * example, waiting for a collection of Futures to complete). 221 * example, waiting for a collection of Futures to complete).
200 */ 222 */
201 class Futures { 223 class Futures {
202 /** 224 /**
203 * Returns a future which will complete once all the futures in a list are 225 * Returns a future which will complete once all the futures in a list are
204 * complete. If any of the futures in the list completes with an exception, 226 * complete. If any of the futures in the list completes with an exception,
205 * the resulting future also completes with an exception. (The value of the 227 * the resulting future also completes with an exception. (The value of the
(...skipping 25 matching lines...) Expand all
231 future.handleException((exception) { 253 future.handleException((exception) {
232 if (!result.isComplete) { 254 if (!result.isComplete) {
233 completer.completeException(exception, future.stackTrace); 255 completer.completeException(exception, future.stackTrace);
234 } 256 }
235 return true; 257 return true;
236 }); 258 });
237 } 259 }
238 return result; 260 return result;
239 } 261 }
240 } 262 }
OLDNEW
« no previous file with comments | « no previous file | lib/coreimpl/future_implementation.dart » ('j') | tests/corelib/future_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698