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

Side by Side Diff: packages/analyzer/lib/exception/exception.dart

Issue 2990843002: Removed fixed dependencies (Closed)
Patch Set: Created 3 years, 4 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
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 library analyzer.exception.exception;
6
7 /**
8 * An exception that occurred during the analysis of one or more sources.
9 */
10 class AnalysisException implements Exception {
11 /**
12 * The message that explains why the exception occurred.
13 */
14 final String message;
15
16 /**
17 * The exception that caused this exception, or `null` if this exception was
18 * not caused by another exception.
19 */
20 final CaughtException cause;
21
22 /**
23 * Initialize a newly created exception to have the given [message] and
24 * [cause].
25 */
26 AnalysisException([this.message = 'Exception', this.cause = null]);
27
28 String toString() {
29 StringBuffer buffer = new StringBuffer();
30 buffer.write("AnalysisException: ");
31 buffer.writeln(message);
32 if (cause != null) {
33 buffer.write('Caused by ');
34 cause._writeOn(buffer);
35 }
36 return buffer.toString();
37 }
38 }
39
40 /**
41 * An exception that was caught and has an associated stack trace.
42 */
43 class CaughtException implements Exception {
44 /**
45 * The exception that was caught.
46 */
47 final Object exception;
48
49 /**
50 * The stack trace associated with the exception.
51 */
52 StackTrace stackTrace;
53
54 /**
55 * Initialize a newly created caught exception to have the given [exception]
56 * and [stackTrace].
57 */
58 CaughtException(this.exception, stackTrace) {
59 if (stackTrace == null) {
60 try {
61 throw this;
62 } catch (_, st) {
63 stackTrace = st;
64 }
65 }
66 this.stackTrace = stackTrace;
67 }
68
69 @override
70 String toString() {
71 StringBuffer buffer = new StringBuffer();
72 _writeOn(buffer);
73 return buffer.toString();
74 }
75
76 /**
77 * Write a textual representation of the caught exception and its associated
78 * stack trace.
79 */
80 void _writeOn(StringBuffer buffer) {
81 if (exception is AnalysisException) {
82 AnalysisException analysisException = exception;
83 buffer.writeln(analysisException.message);
84 if (stackTrace != null) {
85 buffer.writeln(stackTrace.toString());
86 }
87 CaughtException cause = analysisException.cause;
88 if (cause != null) {
89 buffer.write('Caused by ');
90 cause._writeOn(buffer);
91 }
92 } else {
93 buffer.writeln(exception.toString());
94 if (stackTrace != null) {
95 buffer.writeln(stackTrace.toString());
96 }
97 }
98 }
99 }
OLDNEW
« no previous file with comments | « packages/analyzer/lib/error/listener.dart ('k') | packages/analyzer/lib/file_system/file_system.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698