https://stackoverflow.com/questions/47015693/how-to-fix-throw-of-exception-caught-locally

1
2
3
4
5
6
7
8
function(){
try{
if(xxx){
throw new Exception("error");
}
}catch(){
}
}

when throw an exception in try statement, will show an warning:

1
'throw' of exception caught locally. This inspection reports any instances of JavaScript throw statements whose exceptions are always caught by containing try statements. Using throw statements as a "goto" to change the local flow of control is likely to be confusing.

if this is a promise or async function, await is a kind of promise, u can return an reject.

1
2
3
4
5
6
7
8
9
async function(name){
try{
let valid = await check(name);
if(valid){
return Promise.reject("error");
}
}catch(){
}
}

normally, packing this exception in an function

1
2
3
4
5
6
7
8
9
10
11
12
function checkHandle(valid){
if(valid){
throw Error("error");
}
}
async function(name){
try{
let valid = await check(name);
checkHandle(valid);
}catch(){
}
}