2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-08-21 20:42:48 -04:00
|
|
|
import { ErrorKind } from "gen/cli/msg_generated";
|
2019-03-30 14:45:36 -04:00
|
|
|
export { ErrorKind } from "gen/cli/msg_generated";
|
2018-08-15 23:36:48 -04:00
|
|
|
|
2018-10-14 16:29:50 -04:00
|
|
|
/** A Deno specific error. The `kind` property is set to a specific error code
|
|
|
|
* which can be used to in application logic.
|
|
|
|
*
|
2019-02-12 10:08:56 -05:00
|
|
|
* try {
|
|
|
|
* somethingThatMightThrow();
|
|
|
|
* } catch (e) {
|
|
|
|
* if (
|
|
|
|
* e instanceof Deno.DenoError &&
|
|
|
|
* e.kind === Deno.ErrorKind.Overflow
|
|
|
|
* ) {
|
|
|
|
* console.error("Overflow error!");
|
|
|
|
* }
|
2018-10-14 16:29:50 -04:00
|
|
|
* }
|
2019-02-12 10:08:56 -05:00
|
|
|
*
|
2018-10-14 16:29:50 -04:00
|
|
|
*/
|
2018-10-07 19:33:30 -04:00
|
|
|
export class DenoError<T extends ErrorKind> extends Error {
|
|
|
|
constructor(readonly kind: T, msg: string) {
|
|
|
|
super(msg);
|
|
|
|
this.name = ErrorKind[kind];
|
2018-08-15 23:36:48 -04:00
|
|
|
}
|
|
|
|
}
|