本文整理汇总了C++中FileException函数的典型用法代码示例。如果您正苦于以下问题:C++ FileException函数的具体用法?C++ FileException怎么用?C++ FileException使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FileException函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FileException
unsigned long File::FileImpl::Write(const void *buf, unsigned long bytes)
{
DWORD WriteBytes = static_cast<DWORD>(bytes);
if (!WriteFile(FileHandle, buf, static_cast<DWORD>(bytes), &WriteBytes, NULL))
throw FileException("Can't write");
return static_cast<unsigned long>(WriteBytes);
}
示例2: FileException
std::string File::readString(size_t len) {
if (!_file)
throw FileException("File is not open");
if ((_mode & FILEMODE_READ) == 0)
throw FileException("Tried to read from file opened in write mode (" + _name.getFullPath() + ")");
std::string s('\0', len);
std::string::iterator is = s.begin();
char c;
while ((c = readByte())) {
*is = c;
}
return s;
}
示例3: FileException
void File::copyFile(const tstring& source, const tstring& target)
{
if (!::CopyFile(formatPath(source).c_str(), formatPath(target).c_str(), FALSE))
{
throw FileException(Util::translateError(GetLastError())); // 2012-05-03_22-05-14_LZE57W5HZ7NI3VC773UG4DNJ4QIKP7Q7AEBLWOA_AA236F48_crash-stack-r502-beta24-x64-build-9900.dmp
}
}
示例4: poco_assert
void FileImpl::renameToImpl(const std::string& path)
{
poco_assert (!_path.empty());
POCO_DESCRIPTOR_STRING(oldNameDsc, _path);
POCO_DESCRIPTOR_STRING(newNameDsc, path);
int res;
if ((res = lib$rename_file(&oldNameDsc, &newNameDsc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) != 1)
{
switch (res & 0x0FFFFFFF)
{
case RMS$_FNF:
throw FileNotFoundException(_path);
case RMS$_DEV:
case RMS$_DNF:
throw PathNotFoundException(_path);
case RMS$_SYN:
throw PathSyntaxException(path);
case RMS$_RMV:
throw FileAccessDeniedException(_path);
case RMS$_PRV:
throw FileAccessDeniedException("insufficient privileges", _path);
default:
throw FileException(path);
}
}
}
示例5: fopen
/** @brief FileReaderDataSource
*
* @todo: document this function
*/
FileReaderDataSource::FileReaderDataSource(std::string FileName)
{
FileHandle = fopen(FileName.c_str(), "rb");
if (FileHandle == NULL)
throw FileException(std::string("Could not open ") + FileName);
reset();
}
示例6: CreateFileW
utils::File::File(const zchar* const filename, FileAccess access, FileShare share,
FileMode mode, FileType type)
{
hFile = CreateFileW(filename, static_cast<DWORD>(access), static_cast<DWORD>(share), nullptr,
static_cast<DWORD>(mode), static_cast<DWORD>(type), nullptr);
if (hFile == INVALID_HANDLE_VALUE)
{
OutputDebugStringW(L"Something is wrong:\n");
auto error = GetLastError();
switch (error)
{
case ERROR_FILE_EXISTS:
OutputDebugStringW(L"File already exists.\n");
throw FileAlreadyExistsException();
case ERROR_FILE_NOT_FOUND:
OutputDebugStringW(L"File not found.\n");
throw FileNotFoundException();
case ERROR_SHARING_VIOLATION:
OutputDebugStringW(L"File cannot be shared.\n");
throw FileSharingViolationException();
default:
OutputDebugStringW(L"Reason is not defined.\n");
throw FileException();
}
}
}
示例7: throw
void DirectoryListing::loadFile(const string& name) throw(FileException, SimpleXMLException) {
string txt;
// For now, we detect type by ending...
string ext = Util::getFileExt(name);
if(Util::stricmp(ext, ".bz2") == 0) {
::File ff(name, ::File::READ, ::File::OPEN);
FilteredInputStream<UnBZFilter, false> f(&ff);
const size_t BUF_SIZE = 64*1024;
AutoArray<char> buf(BUF_SIZE);
size_t len;
size_t bytesRead = 0;
for(;;) {
size_t n = BUF_SIZE;
len = f.read(buf, n);
txt.append(buf, len);
bytesRead += len;
if(SETTING(MAX_FILELIST_SIZE) && bytesRead > (size_t)SETTING(MAX_FILELIST_SIZE)*1024*1024)
break;
if(len < BUF_SIZE)
break;
}
} else if(Util::stricmp(ext, ".xml") == 0) {
int64_t sz = ::File::getSize(name);
if(sz == -1 || sz >= static_cast<int64_t>(txt.max_size()))
throw(FileException(CSTRING(FILE_NOT_AVAILABLE)));
txt.resize((size_t) sz);
size_t n = txt.length();
::File(name, ::File::READ, ::File::OPEN).read(&txt[0], n);
}
loadXML(txt, false);
}
示例8: GetLastError
void SerialChannelImpl::handleError(const std::string& name)
{
std::string errorText;
DWORD error = GetLastError();
switch (error)
{
case ERROR_FILE_NOT_FOUND:
throw FileNotFoundException(name, getErrorText(errorText));
case ERROR_ACCESS_DENIED:
throw FileAccessDeniedException(name, getErrorText(errorText));
case ERROR_ALREADY_EXISTS:
case ERROR_FILE_EXISTS:
throw FileExistsException(name, getErrorText(errorText));
case ERROR_FILE_READ_ONLY:
throw FileReadOnlyException(name, getErrorText(errorText));
case ERROR_CANNOT_MAKE:
case ERROR_INVALID_NAME:
case ERROR_FILENAME_EXCED_RANGE:
throw CreateFileException(name, getErrorText(errorText));
case ERROR_BROKEN_PIPE:
case ERROR_INVALID_USER_BUFFER:
case ERROR_INSUFFICIENT_BUFFER:
throw IOException(name, getErrorText(errorText));
case ERROR_NOT_ENOUGH_MEMORY:
throw OutOfMemoryException(name, getErrorText(errorText));
case ERROR_HANDLE_EOF: break;
default:
throw FileException(name, getErrorText(errorText));
}
}
示例9: GzFileWriter
GzFileWriter(const std::string &filename) {
file = gzopen(filename.c_str(), "wb9");
if (!file) {
fprintf(stderr, "Can't open file '%s' for writing\n", filename.c_str());
throw FileException();
}
}
示例10: GetLastError
void FileImpl::handleLastErrorImpl(const std::string& path)
{
DWORD err = GetLastError();
switch (err)
{
case ERROR_FILE_NOT_FOUND:
throw FileNotFoundException(path, err);
case ERROR_PATH_NOT_FOUND:
case ERROR_BAD_NETPATH:
case ERROR_CANT_RESOLVE_FILENAME:
case ERROR_INVALID_DRIVE:
throw PathNotFoundException(path, err);
case ERROR_ACCESS_DENIED:
throw FileAccessDeniedException(path, err);
case ERROR_ALREADY_EXISTS:
case ERROR_FILE_EXISTS:
throw FileExistsException(path, err);
case ERROR_INVALID_NAME:
case ERROR_DIRECTORY:
case ERROR_FILENAME_EXCED_RANGE:
case ERROR_BAD_PATHNAME:
throw PathSyntaxException(path, err);
case ERROR_FILE_READ_ONLY:
throw FileReadOnlyException(path, err);
case ERROR_CANNOT_MAKE:
throw CreateFileException(path, err);
case ERROR_DIR_NOT_EMPTY:
throw FileException("directory not empty", path, err);
case ERROR_WRITE_FAULT:
throw WriteFileException(path, err);
case ERROR_READ_FAULT:
throw ReadFileException(path, err);
case ERROR_SHARING_VIOLATION:
throw FileException("sharing violation", path, err);
case ERROR_LOCK_VIOLATION:
throw FileException("lock violation", path, err);
case ERROR_HANDLE_EOF:
throw ReadFileException("EOF reached", path, err);
case ERROR_HANDLE_DISK_FULL:
case ERROR_DISK_FULL:
throw WriteFileException("disk is full", path, err);
case ERROR_NEGATIVE_SEEK:
throw FileException("negative seek", path, err);
default:
throw FileException(path, err);
}
}
示例11: dcassert
void File::setEOF()
{
dcassert(isOpen());
if (!SetEndOfFile(h))
{
throw FileException(Util::translateError(GetLastError()));
}
}
示例12: FileException
std::size_t FileInputStream::available() const
{
long temp = std::ftell(_fp);
if (temp == -1L)
throw FileException();
return _fileSize - temp;
}
示例13: FileException
unsigned int
ReadableFromZCSV::read(const std::string& string, unsigned int pos, ReadableFromZCSV* data)
{
pos = data->readFromString(string, pos);
if (static_cast<int>(pos) < 0)
throw FileException(m_fileName, "Failed to read an element.");
return (pos);
}
示例14: throw
void File::movePos(int64_t pos) throw(FileException)
{
// [!] IRainman use SetFilePointerEx function!
LARGE_INTEGER x = {0};
x.QuadPart = pos;
if (!::SetFilePointerEx(h, x, &x, FILE_CURRENT))
throw(FileException(Util::translateError(GetLastError()))); //[+]PPA
}
示例15: FileException
void utils::File::Write(const void * data, zuint32 count) const
{
zuint32l bytesWritten = 0;
if (!WriteFile(hFile, data, count, &bytesWritten, nullptr))
{
throw FileException();
}
}