From b9510d8a3ac9a86329b0e0acb3a7c09514ab225e Mon Sep 17 00:00:00 2001 From: starg Date: Sat, 13 Aug 2016 11:44:27 +0900 Subject: [PATCH] =?utf8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E5=85=A5?= =?utf8?q?=E5=87=BA=E5=8A=9B=E3=81=AE=E4=BE=8B=E5=A4=96=E5=87=A6=E7=90=86?= =?utf8?q?=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/driver/file.hpp | 12 ++++++++++++ src/driver/file_cpp.cpp | 4 ++-- src/driver/file_win.cpp | 2 +- src/driver/yamml.cpp | 13 +++++++++++-- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/driver/file.hpp b/src/driver/file.hpp index 24738f4..69cf66a 100644 --- a/src/driver/file.hpp +++ b/src/driver/file.hpp @@ -16,11 +16,23 @@ namespace Driver class IOException : public std::runtime_error { public: + using runtime_error::runtime_error; + IOException() : runtime_error("IOException") { } }; +class FileOpenException : public IOException +{ +public: + FileOpenException(const std::string filePath) + : IOException("FileOpenException: Unable to open file '" + filePath + "'"), FilePath(filePath) + { + } + + std::string FilePath; +}; std::string ReadTextFile(const std::string& filePath); void WriteBinaryFile(const std::string& filePath, const std::vector& buffer); diff --git a/src/driver/file_cpp.cpp b/src/driver/file_cpp.cpp index 138e776..03e0ca3 100644 --- a/src/driver/file_cpp.cpp +++ b/src/driver/file_cpp.cpp @@ -25,7 +25,7 @@ std::string ReadTextFile(const std::string& filePath) if (!ifs) { - throw IOException(); + throw FileOpenException(filePath); } std::ostringstream oss; @@ -45,7 +45,7 @@ void WriteBinaryFile(const std::string& filePath, const std::vector(buffer.data()), buffer.size()); diff --git a/src/driver/file_win.cpp b/src/driver/file_win.cpp index 438b7a4..808c570 100644 --- a/src/driver/file_win.cpp +++ b/src/driver/file_win.cpp @@ -95,7 +95,7 @@ public: if (!IsOpened()) { - throw IOException(); + throw FileOpenException(W2UTF8(filePath)); } } diff --git a/src/driver/yamml.cpp b/src/driver/yamml.cpp index a6e465b..c4c2290 100644 --- a/src/driver/yamml.cpp +++ b/src/driver/yamml.cpp @@ -15,6 +15,7 @@ #endif // _WIN32 #include "driver.hpp" +#include "file.hpp" #include "msgcallback.hpp" #include "stderrwriter.hpp" @@ -96,7 +97,7 @@ int main(int argc, char** argv) PO::notify(vm); - if (vm.count("help")) + if (vm.count("help") || !vm.count("input")) { std::cout << "Usage: yamml [...] []\n\n"; std::cout << visibleOptions << std::endl; @@ -115,7 +116,15 @@ int main(int argc, char** argv) return 0; } - + std::cout.flush(); + } + catch (const YAMML::Driver::FileOpenException& e) + { + std::cout << "Unable to open file '" << e.FilePath << "'" << std::endl; + } + catch (const YAMML::Driver::IOException&) + { + std::cout << "Unable to read/write file" << std::endl; } catch (const PO::unknown_option& e) { -- 2.11.0