小编Muh*_*man的帖子

如何在不抛出的情况下抛出错误

最近我被问到一个问题:

有没有办法在不使用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

javascript error-handling try-catch

5
推荐指数
1
解决办法
903
查看次数

从字符串C++中删除元音

所以我是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)

c++ regex string str-replace

0
推荐指数
1
解决办法
2641
查看次数