Skip to content

Commit

Permalink
added extra exception infos
Browse files Browse the repository at this point in the history
  • Loading branch information
odahcam committed Oct 29, 2020
1 parent fb66424 commit ef36ebe
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/core/ArgumentException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ import Exception from './Exception';
/**
* Custom Error class of type Exception.
*/
export default class ArgumentException extends Exception {}
export default class ArgumentException extends Exception {
static readonly kind: string = 'ArgumentException';
}
4 changes: 3 additions & 1 deletion src/core/ArithmeticException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ import Exception from './Exception';
/**
* Custom Error class of type Exception.
*/
export default class ArithmeticException extends Exception {}
export default class ArithmeticException extends Exception {
static readonly kind: string = 'ArithmeticException';
}
1 change: 1 addition & 0 deletions src/core/ArrayIndexOutOfBoundsException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import IndexOutOfBoundsException from './IndexOutOfBoundsException';
* Custom Error class of type Exception.
*/
export default class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException {
static readonly kind: string = 'ArrayIndexOutOfBoundsException';
constructor(
public index: number = undefined,
public message: string = undefined
Expand Down
1 change: 1 addition & 0 deletions src/core/ChecksumException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Exception from './Exception';
* Custom Error class of type Exception.
*/
export default class ChecksumException extends Exception {
static readonly kind: string = 'ChecksumException';
static getChecksumInstance(): ChecksumException {
return new ChecksumException();
}
Expand Down
10 changes: 10 additions & 0 deletions src/core/Exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { CustomError } from 'ts-custom-error';
*/
export default class Exception extends CustomError {

/**
* It's typed as string so it can be extended and overriden.
*/
static readonly kind: string = 'Exception';

/**
* Allows Exception to be constructed directly
* with some message and prototype definition.
Expand All @@ -14,4 +19,9 @@ export default class Exception extends CustomError {
) {
super(message);
}

public getKind(): string {
const ex = <typeof Exception>this.constructor;
return ex.kind;
}
}
2 changes: 2 additions & 0 deletions src/core/FormatException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Exception from './Exception';
*/
export default class FormatException extends Exception {

static readonly kind: string = 'FormatException';

static getFormatInstance(): FormatException {
return new FormatException();
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/IllegalArgumentException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ import Exception from './Exception';
/**
* Custom Error class of type Exception.
*/
export default class IllegalArgumentException extends Exception {}
export default class IllegalArgumentException extends Exception {
static readonly kind: string = 'IllegalArgumentException';
}
4 changes: 3 additions & 1 deletion src/core/IllegalStateException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ import Exception from './Exception';
/**
* Custom Error class of type Exception.
*/
export default class IllegalStateException extends Exception {}
export default class IllegalStateException extends Exception {
static readonly kind: string = 'IllegalStateException';
}
4 changes: 3 additions & 1 deletion src/core/IndexOutOfBoundsException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ import Exception from './Exception';
/**
* Custom Error class of type Exception.
*/
export default class IndexOutOfBoundsException extends Exception {}
export default class IndexOutOfBoundsException extends Exception {
static readonly kind: string = 'IndexOutOfBoundsException';
}
1 change: 1 addition & 0 deletions src/core/NotFoundException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Exception from './Exception';
* Custom Error class of type Exception.
*/
export default class NotFoundException extends Exception {
static readonly kind: string = 'NotFoundException';
static getNotFoundInstance(): NotFoundException {
return new NotFoundException();
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/NullPointerException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ import Exception from './Exception';
/**
* Custom Error class of type Exception.
*/
export default class NullPointerException extends Exception {}
export default class NullPointerException extends Exception {
static readonly kind: string = 'NullPointerException';
}
4 changes: 3 additions & 1 deletion src/core/ReaderException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ import Exception from './Exception';
/**
* Custom Error class of type Exception.
*/
export default class ReaderException extends Exception {}
export default class ReaderException extends Exception {
static readonly kind: string = 'ReaderException';
}
4 changes: 3 additions & 1 deletion src/core/ReedSolomonException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ import Exception from './Exception';
/**
* Custom Error class of type Exception.
*/
export default class ReedSolomonException extends Exception {}
export default class ReedSolomonException extends Exception {
static readonly kind: string = 'ReedSolomonException';
}
4 changes: 3 additions & 1 deletion src/core/UnsupportedOperationException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ import Exception from './Exception';
/**
* Custom Error class of type Exception.
*/
export default class UnsupportedOperationException extends Exception {}
export default class UnsupportedOperationException extends Exception {
static readonly kind: string = 'UnsupportedOperationException';
}
4 changes: 3 additions & 1 deletion src/core/WriterException.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ import Exception from './Exception';
/**
* Custom Error class of type Exception.
*/
export default class WriterException extends Exception {}
export default class WriterException extends Exception {
static readonly kind: string = 'WriterException';
}

0 comments on commit ef36ebe

Please sign in to comment.