コンストラクターでユーザーが入力した不正な値をチェックするクラス「Texture」があります。ユーザーが不正な値を入力すると、コンストラクターは 2 つの例外のいずれかをスローし、実行はコンストラクターから関連する catch ブロックにブレークします。以下のコードを参照してください。
SSViewer::SSViewer(System::Windows::Forms::Form ^ parentForm, GLsizei iWidth, GLsizei iHeight) : COpenGL(parentForm,iWidth,iHeight)
{
printf("\nSuper inherited COGL const func GO");
cbColour = gcnew array<GLfloat>(4);
cbColour[0] = 0.7f;
cbColour[1] = 0.2f;
cbColour[2] = 0.6f;
cbColour[3] = 0.4f;
//Test Texture
try
{
//Test Texture
Texture* myTex = new Texture("C4 Games 2.png");
}
catch(Texture::nonPOTException& e)
{
System::String^ err = gcnew System::String(e.what());
MessageBox::Show(err, "Sprite Sheet Error", MessageBoxButtons::OK, MessageBoxIcon::Stop);
}
catch(Texture::InvalidSizeException& e)
{
System::String^ err = gcnew System::String(e.what());
MessageBox::Show(err, "Sprite Sheet Error", MessageBoxButtons::OK, MessageBoxIcon::Stop);
}
}
この線:
Texture* myTex = new Texture("C4 Games 2.png");
例外をスローする行です。ただし、スローした場合、コントロールは myTex の構築が完了する前に catch ブロックに返されます。明らかに、Texture* のこの不完全で違法に初期化されたインスタンスが存在することは望ましくありません。
私が知りたいのは、スローによって構築が中止された場合、まだ使用中の不完全なインスタンスに使用されるメモリです。delete
メモリを解放するには、catch ブロックで myTexを呼び出す必要がありますか?