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

Side by Side Diff: sdk/lib/core/exceptions.dart

Issue 11369243: Make Exception a class, not an interface, and remove the const constructor. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated. Moved safeToString to Error. Created 8 years, 1 month 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 | « sdk/lib/core/errors.dart ('k') | sdk/lib/html/dart2js/html_dart2js.dart » ('j') | no next file with comments »
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 // Exceptions are thrown either by the VM or from Dart code. 5 // Exceptions are thrown either by the VM or from Dart code.
6 6
7 /** 7 /**
8 * Interface implemented by all core library exceptions. 8 * A marker interface implemented by all core library exceptions.
9 * Defaults to an implementation that only carries a simple message. 9 *
10 * An [Exception] is intended to convey information to the user about a failure,
11 * so that the error can be addressed programmatically. It is intended to be
12 * caught, and it should contain useful data fields.
13 *
14 * Creating instances of [Exception] directly with [:new Exception("message"):]
15 * is discouraged, and only included as a temporary measure during development,
16 * until the actual exceptions used by a library are done.
10 */ 17 */
11 abstract class Exception { 18 abstract class Exception {
12 const factory Exception([var message]) = _ExceptionImplementation; 19 factory Exception([var message]) => new _ExceptionImplementation(message);
13 } 20 }
14 21
15 22
16 /** Default implementation of [Exception] which carries a message. */ 23 /** Default implementation of [Exception] which carries a message. */
17 class _ExceptionImplementation implements Exception { 24 class _ExceptionImplementation implements Exception {
18 final message; 25 final message;
19 const _ExceptionImplementation([this.message]); 26
20 String toString() => (message == null) ? "Exception" : "Exception: $message"; 27 _ExceptionImplementation([this.message]);
28
29 String toString() {
30 if (message == null) return "Exception";
31 return "Exception: $message";
32 }
21 } 33 }
22 34
23 35
24 /** 36 /**
25 * Exception thrown when a string or some other data does not have an expected 37 * Exception thrown when a string or some other data does not have an expected
26 * format and cannot be parsed or processed. 38 * format and cannot be parsed or processed.
27 */ 39 */
28 class FormatException implements Exception { 40 class FormatException implements Exception {
29 /** 41 /**
30 * A message describing the format error. 42 * A message describing the format error.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 85 }
74 86
75 /** 87 /**
76 * Exception thrown when a runtime error occurs. 88 * Exception thrown when a runtime error occurs.
77 */ 89 */
78 class RuntimeError implements Exception { 90 class RuntimeError implements Exception {
79 final message; 91 final message;
80 RuntimeError(this.message); 92 RuntimeError(this.message);
81 String toString() => "RuntimeError: $message"; 93 String toString() => "RuntimeError: $message";
82 } 94 }
OLDNEW
« no previous file with comments | « sdk/lib/core/errors.dart ('k') | sdk/lib/html/dart2js/html_dart2js.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698