我是编程概念的新手,也是我第一次使用 Visual Studio 等软件。所以现在我正在学习C++语言。
当我尝试处理 C++ 中的 error ()
函数时,它给我一条错误消息,提示 "ConsoleApplication3.exe 中 0x76DE3E28 处未处理的异常:Microsoft C++ 异常:内存位置的 std::runtime_error 0x0116F8CC.”。这是我的代码示例:
#include "stdafx.h"
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
#include <algorithm>
#include "std_lib_facilities.h"
using namespace std;
int area(int w , int l)
{
if (w <= 0 || l <= 0) error("There's something went wrong!");
return w / l;
}
int main()
{
int x = 3;
int y = 0;
cout << area(x, y) << endl;
keep_window_open();
}
我检查了很多次,没有发现代码有什么问题。我对该代码做错了什么吗?请帮我解决这些问题。非常感谢!!
最佳答案
这是 Bjarne Stroustrup 的标题之一。如果查看异常发生的位置,您会看到正在抛出异常。你所看到的是预期的。您不应该对刚从某处获得的代码做出假设。创建您自己的错误函数并使其执行您要查找的操作。
关于c++ - c++ 中的“error ()”函数不适用于 Visual Studio 2015,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39682493/