本文整理汇总了C++中Error::convertToErrorCode方法的典型用法代码示例。如果您正苦于以下问题:C++ Error::convertToErrorCode方法的具体用法?C++ Error::convertToErrorCode怎么用?C++ Error::convertToErrorCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Error
的用法示例。
在下文中一共展示了Error::convertToErrorCode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: errorCodeToError
~CacheStream() {
// Make sure the stream is closed before committing it.
OS.reset();
// Open the file first to avoid racing with a cache pruner.
ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
MemoryBuffer::getOpenFile(TempFile.FD, TempFile.TmpName,
/*FileSize*/ -1,
/*RequiresNullTerminator*/ false);
if (!MBOrErr)
report_fatal_error(Twine("Failed to open new cache file ") +
TempFile.TmpName + ": " +
MBOrErr.getError().message() + "\n");
// On POSIX systems, this will atomically replace the destination if
// it already exists. We try to emulate this on Windows, but this may
// fail with a permission denied error (for example, if the destination
// is currently opened by another process that does not give us the
// sharing permissions we need). Since the existing file should be
// semantically equivalent to the one we are trying to write, we give
// AddBuffer a copy of the bytes we wrote in that case. We do this
// instead of just using the existing file, because the pruner might
// delete the file before we get a chance to use it.
Error E = TempFile.keep(EntryPath);
E = handleErrors(std::move(E), [&](const ECError &E) -> Error {
std::error_code EC = E.convertToErrorCode();
if (EC != errc::permission_denied)
return errorCodeToError(EC);
auto MBCopy = MemoryBuffer::getMemBufferCopy((*MBOrErr)->getBuffer(),
EntryPath);
MBOrErr = std::move(MBCopy);
// FIXME: should we consume the discard error?
consumeError(TempFile.discard());
return Error::success();
});
if (E)
report_fatal_error(Twine("Failed to rename temporary file ") +
TempFile.TmpName + " to " + EntryPath + ": " +
toString(std::move(E)) + "\n");
AddBuffer(Task, std::move(*MBOrErr));
}