c++ - try catch __finally 在 C++ Builder 中使用

标签 c++ c++builder try-catch-finally

我认为这段代码是否正确:

try
    {
    Screen->Cursor = crHourGlass;
    try
        {
        throw Exception("error!");
        }
    catch(Exception& e)
        {
        Application->MessageBox(UnicodeString(e.Message).c_str(), L"Error", MB_OK);
        }
    }
__finally
    {
    Screen->Cursor = crDefault;
    }

实际上与这个相同,__finally 在这里没有任何作用,因为在这两种情况下,Screen->Cursor = crDefault 都会被执行?

Screen->Cursor = crHourGlass;
try
    {
    throw Exception("error!");
    }
catch(Exception& e)
    {
    Application->MessageBox(UnicodeString(e.Message).c_str(), L"Error", MB_OK);
    }
Screen->Cursor = crDefault;

最佳答案

不,因为您只捕获 Exception 类型的异常。如果发生其他异常,则 Screen->Cursor = crDefault 将不会在第二版代码中执行。

关于c++ - try catch __finally 在 C++ Builder 中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35728957/

相关文章:

c# - 如果 finally block 抛出异常会怎样?

c++ - 表达式模板 - 无法专门化函数模板

c++ - 对话框在 VS2015 中显示为黑色

c++ - 如何从另一个类调用静态方法?

php - 我可以像这样使用 try-catch-finally 吗?

php - PHP 中的 `finally` 关键字是什么?

c++ - 带有 C++ 插件的 Node 应用程序在运行时提示 undefined symbol

linux 的 c++ 应用程序将 ipv4 数据包转换为 ipv6

c++ - 在阻塞模式下使用 TServerSocket 时如何处理异常?

delphi - 如何在 C++Builder 中构造这个 Delphi 类?