Skip to content

Commit

Permalink
fix: custom Exception extends Error
Browse files Browse the repository at this point in the history
  • Loading branch information
luomingtao committed Mar 28, 2019
1 parent 1d9c5cc commit 45c9f5f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/FailedPredicateException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export class FailedPredicateException extends RecognitionException {
recognizer.inputStream,
recognizer.context,
FailedPredicateException.formatMessage(predicate, message));
Object.setPrototypeOf(this, FailedPredicateException.prototype);

let s: ATNState = recognizer.interpreter.atn.states[recognizer.state];

let trans = s.transition(0) as AbstractPredicateTransition;
Expand Down
1 change: 1 addition & 0 deletions src/InputMismatchException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class InputMismatchException extends RecognitionException {
}

super(recognizer, recognizer.inputStream, context);
Object.setPrototypeOf(this, InputMismatchException.prototype);

if (state !== undefined) {
this.setOffendingState(state);
Expand Down
2 changes: 2 additions & 0 deletions src/LexerNoViableAltException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export class LexerNoViableAltException extends RecognitionException {
startIndex: number,
deadEndConfigs: ATNConfigSet | undefined) {
super(lexer, input);
Object.setPrototypeOf(this, LexerNoViableAltException.prototype);

this._startIndex = startIndex;
this._deadEndConfigs = deadEndConfigs;
}
Expand Down
2 changes: 2 additions & 0 deletions src/NoViableAltException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export class NoViableAltException extends RecognitionException {
}

super(recognizer, input, ctx);
Object.setPrototypeOf(this, NoViableAltException.prototype);

this._deadEndConfigs = deadEndConfigs;
this._startToken = startToken as Token;
this.setOffendingToken(recognizer, offendingToken);
Expand Down
2 changes: 2 additions & 0 deletions src/RecognitionException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export class RecognitionException extends Error {
if (recognizer) {
this._offendingState = recognizer.state;
}
// see https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work
Object.setPrototypeOf(this, RecognitionException.prototype);
}

/**
Expand Down

0 comments on commit 45c9f5f

Please sign in to comment.