C++Builder About noexcept & throw[JAPAN]
"noexcept" has been added since C++11. The "throw" attached to the method from C++1z(17) may be an error.
////
void func() throw() {} //C++17 Error
void func() {} //C++17 OK
It is possible to add "noexcept" to a method from C++11.
////
void func() noexcept(false)
{
throw std::runtime_error("error");
}
//Exception handling is ignored if it is below.
void func() noexcept //noexcept(true)
{
throw std::runtime_error("error");
}
The following is how to use in the internal method.
////
void __fastcall TForm1::Button2Click(TObject *Sender)
{
int i = noexcept(StrToInt("A")); //There is also this usage.
Memo1->Lines->Append((String)i);
}
////
void __fastcall TForm1::Button2Click(TObject *Sender)
{
TComponent* c1;// = new TComponent(this);
int i = noexcept((int)c1->Tag); //It does not cause an error.
Memo1->Lines->Append(static_cast<String>(i));
}
Considering the future, it is better not to use "throw" after the method.
It's because of the transition to "C++1z".