Skip to content

Commit

Permalink
feat(lang): added "context" to BaseException
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Jul 22, 2015
1 parent 8ad4ad5 commit 8ecb632
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions modules/angular2/src/core/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ function _createNgZone(givenReporter: Function): NgZone {
var defaultErrorReporter = (exception, stackTrace) => {
var longStackTrace = ListWrapper.join(stackTrace, "\n\n-----async gap-----\n");
DOM.logError(`${exception}\n\n${longStackTrace}`);

if (exception instanceof BaseException && isPresent(exception.context)) {
print("Error Context:");
print(exception.context);
}
throw exception;
};

Expand Down
5 changes: 3 additions & 2 deletions modules/angular2/src/facade/lang.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,12 @@ class FunctionWrapper {
}

class BaseException extends Error {
final dynamic context;
final String message;
final originalException;
final originalStack;

BaseException([this.message, this.originalException, this.originalStack]);
BaseException([this.message, this.originalException, this.originalStack, this.context]);

String toString() {
return this.message;
Expand Down Expand Up @@ -225,7 +226,7 @@ bool isJsObject(o) {

var _assertionsEnabled = null;
bool assertionsEnabled() {
if (_assertionsEnabled == null) {
if (_assertionsEnabled == null) {
try {
assert(false);
_assertionsEnabled = false;
Expand Down
13 changes: 11 additions & 2 deletions modules/angular2/src/facade/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ export function getTypeNameForDebugging(type: Type): string {

export class BaseException extends Error {
stack;
constructor(public message?: string, public originalException?, public originalStack?) {
constructor(public message?: string, private _originalException?, private _originalStack?,
private _context?) {
super(message);
this.stack = (<any>new Error(message)).stack;
}

get originalException(): any { return this._originalException; }

get originalStack(): any { return this._originalStack; }

get context(): any { return this._context; }

toString(): string { return this.message; }
}

Expand Down Expand Up @@ -118,7 +125,9 @@ export function stringify(token): string {
return token.name;
}

return token.toString();
var res = token.toString();
var newLineIndex = res.indexOf("\n");
return (newLineIndex === -1) ? res : res.substring(0, newLineIndex);
}

export class StringWrapper {
Expand Down

0 comments on commit 8ecb632

Please sign in to comment.