noldova.context.exceptions
CONTEXT库抛出的异常:一个抽象 Exception 基础名称
在它的具体类之后本身,参数异常带有检查a
值并在一次调用中缩小其类型,以及索引异常。
安装
npm install @noldova/context.exceptions
使用
import { ArgumentException, ArgumentNullException, Exception, ExceptionOptions } from "@noldova/context.exceptions";
class InputException extends Exception {
public constructor(message: string, options?: ExceptionOptions) {
super(message, options);
}
}
function readName(values: Map<string, string>): string {
const name = values.get("name");
ArgumentException.throwIfNullOrWhitespace(name, "name");
return name; // Narrowed to string by the guard.
}
readName(new Map([["name", "Fixture"]])); // "Fixture"
new ArgumentNullException("input").message; // "Value cannot be null or undefined. (Parameter 'input')"
new InputException("Cannot read input.", new ExceptionOptions(new Error("Bad encoding."))).name; // "InputException"
ArgumentException, ArgumentNullException 和 ArgumentOutOfRangeException
将参数名称保留为字段,并且 ArgumentOutOfRangeException 也保持
被拒绝的值。 IndexOutOfRangeException 携带信息and, where
给定,一个原因。声明文件 api/index.d.ts 记录每个成员
有合同和例子。
许可证
麻省理工学院;看到 LICENSE.