异常处理的基本问题
In the following example, the try block attempts to write the headers. The catch block then handles a specific file exception, and passes all other exceptions on to the outer block with the throw macro:
// Example of the try and catch statements
try
{
// Write the file header
file.Write((LPSTR)&bmfHdr, sizeof(BITMAPFILEHEADER));
//
// Write the DIB header and the bits
file.WriteHuge(lpBI, dwDIBSize);
}
catch (CFileException* e)
{
::GlobalUnlock((HGLOBAL) hDib);
throw;
}
::GlobalUnlock((HGLOBAL) hDib);
return TRUE;
请问,若try块中若无异常出现,则直接执行::GlobalUnlock((HGLOBAL) hDib);
return TRUE;
是吗?
又try 块中无throw ,怎么把异常抛掷到catch块?
catch块中的throw 若起作用,是否就不执行::GlobalUnlock((HGLOBAL) hDib);
return TRUE;
这两条语句。