是C++预计将在Main()中处理例外?

发布于 2025-02-03 05:28:15 字数 352 浏览 3 评论 0原文

我正在C ++做一个项目,而我是OOP的新手。

我对C ++例外以及必须处理的地方有一些疑问。 我读到,将try/Catch块插入main()函数的好习惯是一种很好的做法main()并在此处处理,在这种情况下对用户反馈进行编程。

问题在于,并非所有项目的错误都被视为例外,因此,在main()中称为高级函数返回一个BOOL值,该值是错误状态的第一个指标。

因此,我想知道不处理main()中的异常是一件好事false在高水平的值中捕获异常时,使我能够以相同的方式对待所有错误。

I am doing a project in C++, and I am new to OOP.

I have some doubts regarding C++ exceptions and where they have to be handled.
I read that it is a good practice to insert the try/catch block into the main() function, letting the exceptions thrown into "deep placed" methods to climb up to main() and be handled there, programming the user feedback in such cases.

The problem is that not all the errors of the project are treated like exceptions, and for that reason high level functions called in main() return a bool value that is a first indicator of an error state.

So, I am wondering whether it is a good thing not to handle exceptions in main() in that case, placing the try/catch block into low-level methods and returning a false value in the high-level one when an exception has been caught in the former, allowing me to treat all the errors the same way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请别遗忘我 2025-02-10 05:28:15

没有一般规则这些处理程序应该去。

但是,您将您的程序描述为“ main()返回bool值的高级功能”。这是一个合理的选择:这些高级功能都会照顾任何特定的例外处理。从main的角度来看,这些高级功能要么成功或失败。因此,main在您的特定设计中无需打扰异常。

There is no general rule where these handlers should go.

But you describe your program as "high level functions called in main() return a bool value". That is a reasonable choice: any specific exception handling is taken care of by those high-level functions. From the perspective of main, these high-level functions either succeed or they fail. Hence, main does not need to bother with exceptions in your specific design.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文