以下代码可以编译通过,可是为什么当我把hello.txt用word打开后再运行这个代码弹出的对话框的内容是操作系统的提示“在存取 d:\hello.txt 时发生共享违例。”而不是我自己定义的“Sharing Violation!”呢?
但是当两个“////////????????????????????”之间的部分改为“
catch (CFileException *e) {
switch(e->m_cause) {”之后又可以按我自定义的提示呢?////////////////////////////////Begin////////////////////////////////
CString str = "Hello World!";
CString strPath = "d:\\hello.txt"; try {
CFile file(strPath, CFile::modeCreate |CFile::modeWrite);
file.Write(str,str.GetLength());
file.Close();
}
////////????????????????????
catch (CFileException e) {
switch(e.m_cause) {
////////????????????????????
case CFileException::sharingViolation:
MessageBox("Sharing Violation!");
break;
case CFileException::badPath:
MessageBox("Invalid Path!");
break;
}
}
/////////////////////////////////End//////////////////////////////////