【发布时间】:2016-03-01 17:04:14
【问题描述】:
我认为这段代码是否正确:
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;
【问题讨论】:
-
不应该首先尝试
__try来匹配微软特定的__finally吗? -
@flatmouse:不在 C++Builder 中,不。
try/__finally是一个有效的组合。 -
仅供参考,
UnicodeString(e.Message).c_str()是多余的,因为e.Message是System::String和TApplicaton::MessageBox()期望System::Char*值作为输入,因此您可以删除类型转换:Application->MessageBox(e.Message.c_str(), L"Error", MB_OK);
标签: c++ c++builder try-catch-finally