最近我被问到一个问题:
throwjavaScript的情况下抛出错误?据我所知,错误只有一种方法可以在JavaScript中抛出错误,并且在JavaScript中使用throw语句如下:
var myFunc = () => {
// some code here
throw 'Some error' // in a conditional
// some more code
}
try {
myFunc()
}catch(e) {
console.log(e)
}Run Code Online (Sandbox Code Playgroud)
而且不知道我说的任何其他方式No, there is no other way.但现在我想知道我是不对的?
所以问题是你是否可以在不使用的情况下在JavaScript中抛出自定义错误throw
eval,Function.throw在你的代码中使用如果你可以在不使用单词的情况下抛出错误 Error
所以我是C++的新手,并尝试创建一个可以从字符串中删除元音的函数,但是我很失败,到目前为止这是我的代码:
#include <string>
using namespace std;
string remove(string st) {
for(int i = 0; st[i] != '\0'; i++)
st[i] = st[i] == 'a' || st[i] == 'e' || st[i] == 'i' || st[i] == 'o' || st[i] ==
'u' || st[i] == 'A' || st[i] == 'E' || st[i] == 'I' || st[i] == 'O' || st[i] ==
'U' ? '' : st[i];
}
return st;
Run Code Online (Sandbox Code Playgroud)
这似乎引发了一个错误?我知道我做错了什么
我得到的错误是:
main.cpp:10:16: error: expected expression 'U' ? '' : Z[i];
Run Code Online (Sandbox Code Playgroud)
并在另一个解释器上运行:
.code.tio.cpp:7:14: error: …Run Code Online (Sandbox Code Playgroud)