Remove and replace exceptions

This commit is contained in:
2015-07-21 22:37:22 -07:00
parent 7442d618e7
commit 8068ea0d95
33 changed files with 425 additions and 588 deletions

View File

@@ -1,8 +1,4 @@
#include "Athena/FileReader.hpp"
#include "Athena/FileNotFoundException.hpp"
#include "Athena/InvalidDataException.hpp"
#include "Athena/InvalidOperationException.hpp"
#include "Athena/IOException.hpp"
#if _WIN32
#include "win32_largefilewrapper.h"
@@ -35,7 +31,10 @@ void FileReader::open()
m_fileHandle = fopen(m_filename.c_str(), "rb");
if (!m_fileHandle)
THROW_FILE_NOT_FOUND_EXCEPTION(m_filename);
{
atError("File not found '%s'", m_filename.c_str());
return;
}
// ensure we're at the beginning of the file
rewind(m_fileHandle);
@@ -44,7 +43,10 @@ void FileReader::open()
void FileReader::close()
{
if (!m_fileHandle)
THROW_INVALID_OPERATION_EXCEPTION("Cannot close an unopened stream");
{
atError("Cannot close an unopened stream");
return;
}
fclose(m_fileHandle);
m_fileHandle = NULL;
@@ -72,7 +74,8 @@ void FileReader::seek(atInt64 pos, SeekOrigin origin)
if (m_offset > length())
{
oldOff = m_offset;
THROW_INVALID_OPERATION_EXCEPTION("Unable to seek in file");
atError("Unable to seek in file");
return;
}
size_t block = m_offset / m_blockSize;
@@ -84,13 +87,16 @@ void FileReader::seek(atInt64 pos, SeekOrigin origin)
}
}
else if (fseeko64(m_fileHandle, pos, (int)origin) != 0)
THROW_INVALID_OPERATION_EXCEPTION("Unable to seek in file");
atError("Unable to seek in file");
}
atUint64 FileReader::position() const
{
if (!isOpen())
THROW_INVALID_OPERATION_EXCEPTION_RETURN(0, "File not open");
{
atError("File not open");
return 0;
}
if (m_blockSize > 0)
return m_offset;
@@ -101,7 +107,10 @@ atUint64 FileReader::position() const
atUint64 FileReader::length() const
{
if (!isOpen())
THROW_INVALID_OPERATION_EXCEPTION_RETURN(0, "File not open");
{
atError("File not open");
return 0;
}
return utility::fileSize(m_filename);
}
@@ -109,7 +118,10 @@ atUint64 FileReader::length() const
atUint64 FileReader::readUBytesToBuf(void* buf, atUint64 len)
{
if (!isOpen())
THROW_INVALID_OPERATION_EXCEPTION_RETURN(0, "File not open for reading");
{
atError("File not open for reading");
return 0;
}
if (m_blockSize <= 0)
return fread(buf, 1, len, m_fileHandle);