C++/CX 中的 FileNotFoundException 在哪里?
Where is FileNotFoundException in C++/CX?
方法 StorageFolder.GetFolderAsync 应该抛出 FileNotFoundException
但我无法在任何地方找到它。我应该如何处理它抛出的异常?
StorageFolder.GetFolderAsync does not account for exception handling, as implemented in C++/CX (see Exceptions (C++/CX) 文档的 C++/CX 版本:
The Platform namespace defines distinct exception classes for the most common HRESULT values; all other values are reported through the Platform::COMException class.
System Namespace 是 .NET 框架的一部分。因此,它不适用于 C++/CX 代码。 GetFolderAsync
的文档中列出的异常仅在从 .NET 调用该函数时才会抛出。
从 C++/CX 调用时,GetFolderAsync
通过 Platform::COMException
报告失败。 System.IO.FileNotFoundException
的等价物是一个例外,HRESULT
设置为 HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)
(0x80070002).
C++/CX 异常处理程序应该捕获 Platform::COMException
(或 Platform::Exception), and check the Exception::HResult property 以识别特定的异常类型。
参考文献:
方法 StorageFolder.GetFolderAsync 应该抛出 FileNotFoundException
但我无法在任何地方找到它。我应该如何处理它抛出的异常?
StorageFolder.GetFolderAsync does not account for exception handling, as implemented in C++/CX (see Exceptions (C++/CX) 文档的 C++/CX 版本:
The Platform namespace defines distinct exception classes for the most common HRESULT values; all other values are reported through the Platform::COMException class.
System Namespace 是 .NET 框架的一部分。因此,它不适用于 C++/CX 代码。 GetFolderAsync
的文档中列出的异常仅在从 .NET 调用该函数时才会抛出。
从 C++/CX 调用时,GetFolderAsync
通过 Platform::COMException
报告失败。 System.IO.FileNotFoundException
的等价物是一个例外,HRESULT
设置为 HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)
(0x80070002).
C++/CX 异常处理程序应该捕获 Platform::COMException
(或 Platform::Exception), and check the Exception::HResult property 以识别特定的异常类型。
参考文献: