错误 - Error

包括语法错误、类型错误、编译错误、依赖丢失、空指针

警告 - Warning

不符合编码规范、语义有问题,使用了保留字,给出的警告信息

异常 - Exception

程序逻辑、运行没有出错,只是用户的输入、执行不符合我们既定的规则,程序捕获到异常,给出的提示信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const COLOR_RED = "red";
const COLOR_YELLOW = "yellow";
const COLOR_BLUE = "blue";
const MY_BLUE = "blue";

function ColorException(message) {
this.message = message;
this.name = "ColorException";
}

function getConstantName(color) {
switch (color) {
case COLOR_RED:
return "COLOR_RED";
case COLOR_YELLOW:
return "COLOR_YELLOW ";
case COLOR_BLUE:
return "COLOR_BLUE";
case MY_BLUE:
return "MY_BLUE";
default:
throw new ColorException("Can't find this color");
}
}