c++ - c++ 中的“error ()”函数不适用于 Visual Studio 2015

标签 c++ visual-studio-2015 unhandled-exception

我是编程概念的新手,也是我第一次使用 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/

相关文章:

c++ - 存储和访问字符串集合 (STD C++)

c++ - 计算输入文件中的单词添加额外的单词?

c++ - 为什么 clang 找不到在调用站点之前声明的函数?

visual-studio - 使用 Visual Studio 2015 进行调试时无法在 View 中编辑 C# 代码

node.js - Visual Studio 2015 Node 模块中心位置

c++ - file_not_found 错误 - 带有 Visual Studio 2015 的 directx 工具包

Lisp IO 问题

node.js - Node.js 管道中未处理的流错误

flutter - 当我设置超时持续时间时,没有互联网连接的未处理的套接字异常

c++ - 使用嵌套的 if 语句来构造代码