__try
Windows 用の C コードをプログラミングするとき、SEH の...ブロックを使用するように「デフォルト」する__finally
必要がありますか?
言い換えれば、以下のどれが (たとえば) より良いプラクティスと見なされますか? また、その理由は何ですか?
HDC hDCCompat = CreateCompatibleDC(hDC);
__try
{
HBITMAP hBmpCompat = CreateCompatibleBitmap(hDC, ...);
__try
{
SelectObject(hDCCompat, hBmpCompat);
BitBlt(hDC, ..., hDCCompat, ...);
}
__finally { DeleteObject(hBmpCompat); }
}
__finally { DeleteObject(hDCCompat); }
対
HDC hDCCompat = CreateCompatibleDC(hDC);
HBITMAP hBmpCompat = CreateCompatibleBitmap(hDC, ...);
SelectObject(hDCCompat, hBmpCompat);
BitBlt(hDC, ..., hDCCompat, ...);
DeleteObject(hBmpCompat);
DeleteObject(hDCCompat);
明確化
私は言及するのを忘れました:
My idea behind this was that, if someone inserts more code later into the block (e.g. an early return from the function), my code would still perform the cleanup, rather than exiting prematurely. So it was supposed to be more preventive than anything else. Should I still avoid using SEH anyway?