From 812e01faaa17a675a1f473969211fec33c95d4b9 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 4 Sep 2014 01:36:28 +0000 Subject: Refactor FileStream exception throwing. Avoid duplicate reporting, and include a message in the exceptions thrown. Merged back changes from the test refactor branch to reduce diffs. --- lib/common/FileStream.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/common/FileStream.cpp b/lib/common/FileStream.cpp index 99b66666..e38e5d38 100644 --- a/lib/common/FileStream.cpp +++ b/lib/common/FileStream.cpp @@ -67,24 +67,29 @@ void FileStream::AfterOpen() { MEMLEAKFINDER_NOT_A_LEAK(this); - #ifdef WIN32 - BOX_LOG_WIN_WARNING_NUMBER("Failed to open file: " << - mFileName, winerrno); - #else - BOX_LOG_SYS_WARNING("Failed to open file: " << - mFileName); - #endif - +#ifdef WIN32 + if(errno == EACCES) + { + THROW_WIN_FILE_ERROR("Failed to open file", mFileName, + CommonException, AccessDenied); + } + else + { + THROW_WIN_FILE_ERROR("Failed to open file", mFileName, + CommonException, OSFileOpenError); + } +#else if(errno == EACCES) { - THROW_EXCEPTION_MESSAGE(CommonException, AccessDenied, - mFileName); + THROW_SYS_FILE_ERROR("Failed to open file", mFileName, + CommonException, AccessDenied); } else { - THROW_EXCEPTION_MESSAGE(CommonException, OSFileOpenError, - mFileName); + THROW_SYS_FILE_ERROR("Failed to open file", mFileName, + CommonException, OSFileOpenError); } +#endif } } -- cgit v1.2.3