diff --git a/src/core/ArgumentException.ts b/src/core/ArgumentException.ts index f9d65cf7..713d88f4 100644 --- a/src/core/ArgumentException.ts +++ b/src/core/ArgumentException.ts @@ -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'; +} diff --git a/src/core/ArithmeticException.ts b/src/core/ArithmeticException.ts index 8f3359ba..5f503d9e 100644 --- a/src/core/ArithmeticException.ts +++ b/src/core/ArithmeticException.ts @@ -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'; +} diff --git a/src/core/ArrayIndexOutOfBoundsException.ts b/src/core/ArrayIndexOutOfBoundsException.ts index 6ec21041..bff1c11f 100644 --- a/src/core/ArrayIndexOutOfBoundsException.ts +++ b/src/core/ArrayIndexOutOfBoundsException.ts @@ -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 diff --git a/src/core/ChecksumException.ts b/src/core/ChecksumException.ts index 6910c3a5..6041c36f 100644 --- a/src/core/ChecksumException.ts +++ b/src/core/ChecksumException.ts @@ -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(); } diff --git a/src/core/Exception.ts b/src/core/Exception.ts index 73dabb95..965949fc 100644 --- a/src/core/Exception.ts +++ b/src/core/Exception.ts @@ -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. @@ -14,4 +19,9 @@ export default class Exception extends CustomError { ) { super(message); } + + public getKind(): string { + const ex = this.constructor; + return ex.kind; + } } diff --git a/src/core/FormatException.ts b/src/core/FormatException.ts index 0ff02b33..fb636b9a 100644 --- a/src/core/FormatException.ts +++ b/src/core/FormatException.ts @@ -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(); } diff --git a/src/core/IllegalArgumentException.ts b/src/core/IllegalArgumentException.ts index d5a9cc5c..e477da8a 100644 --- a/src/core/IllegalArgumentException.ts +++ b/src/core/IllegalArgumentException.ts @@ -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'; +} diff --git a/src/core/IllegalStateException.ts b/src/core/IllegalStateException.ts index fdfe68d6..b58c2d41 100644 --- a/src/core/IllegalStateException.ts +++ b/src/core/IllegalStateException.ts @@ -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'; +} diff --git a/src/core/IndexOutOfBoundsException.ts b/src/core/IndexOutOfBoundsException.ts index 8b771365..eea17c9c 100644 --- a/src/core/IndexOutOfBoundsException.ts +++ b/src/core/IndexOutOfBoundsException.ts @@ -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'; +} diff --git a/src/core/NotFoundException.ts b/src/core/NotFoundException.ts index 6b41e2ca..17529036 100644 --- a/src/core/NotFoundException.ts +++ b/src/core/NotFoundException.ts @@ -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(); } diff --git a/src/core/NullPointerException.ts b/src/core/NullPointerException.ts index f61d4c8a..00b689af 100644 --- a/src/core/NullPointerException.ts +++ b/src/core/NullPointerException.ts @@ -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'; +} diff --git a/src/core/ReaderException.ts b/src/core/ReaderException.ts index 093ce753..86bb6d54 100644 --- a/src/core/ReaderException.ts +++ b/src/core/ReaderException.ts @@ -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'; +} diff --git a/src/core/ReedSolomonException.ts b/src/core/ReedSolomonException.ts index c9cfb8f9..e73410a6 100644 --- a/src/core/ReedSolomonException.ts +++ b/src/core/ReedSolomonException.ts @@ -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'; +} diff --git a/src/core/UnsupportedOperationException.ts b/src/core/UnsupportedOperationException.ts index ff94adea..34a1cdf4 100644 --- a/src/core/UnsupportedOperationException.ts +++ b/src/core/UnsupportedOperationException.ts @@ -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'; +} diff --git a/src/core/WriterException.ts b/src/core/WriterException.ts index 85489632..08851d00 100644 --- a/src/core/WriterException.ts +++ b/src/core/WriterException.ts @@ -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'; +}