控制台中未显示 Visual C++ 异常 [英] Visual C++ Exception not shown in console

查看:42
本文介绍了控制台中未显示 Visual C++ 异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了一个 C++ 异常并在错误时抛出这个异常而没有捕获它.在 linux 中,我确实在控制台上看到了异常文本(what")并且应用程序存在.这是我预期的行为.

I've implemented a C++ Exception and throw this exception on errors without catching it. In linux I do see the exception text ("what") on console and the application exists. This is my expected behaviour.

在 Windows(使用 Visual C++ 2015 编译)上,但是会打开一个弹出窗口并指出一般错误.我在控制台或其他任何地方都没有看到异常消息.是否也可以在 Windows 上将抛出/未捕获的异常记录到控制台/标准输出(或标准错误)?

On windows (compiled with Visual C++ 2015) however a popup window opens and states a generic error. I do not see the exception message on console or anywhere else. Is it possible to log thrown/uncaught exceptions to console/stdout (or stderr) on Windows, too?

谢谢

推荐答案

抛出未捕获的异常会终止您的程序.无论如何,您的 Linux 工具链都非常友好地显示了消息;当然不需要这样做.此终止计为崩溃,因此会出现弹出窗口.

Throwing an uncaught exception terminates your program. Your Linux toolchain is being very kind by showing the message anyway; it's certainly not required to do so. This termination counts as a crash, hence the popup window.

main 中放置一个 try/catch 对,以安全地捕获所有其他未处理的异常.不过,这不会帮助您构建全局变量.

Put a try/catch pair in main to safely catch all otherwise-unhandled exceptions. This won't help you with construction of your globals, though.

这篇关于控制台中未显示 Visual C++ 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆