From 7be0f56b95a9b72ab8b462064341893151b8ef77 Mon Sep 17 00:00:00 2001 From: namark <nshan.nnnn@gmail.com> Date: Tue, 19 Dec 2017 04:59:10 +0400 Subject: [PATCH] Rudimentary error handling for all tools. --- diff.cpp | 9 ++++++++- glue.cpp | 9 ++++++++- shred.cpp | 9 ++++++++- swap.cpp | 9 ++++++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/diff.cpp b/diff.cpp index 5eb689f..c4558ce 100644 --- a/diff.cpp +++ b/diff.cpp @@ -1,6 +1,7 @@ #include <iostream> #include <algorithm> #include <cmath> +#include <cstring> #include "simple/file.hpp" #include "simple/geom/vector.hpp" #include "simple/support/arithmetic.hpp" @@ -71,7 +72,7 @@ void showChange(index_type position, index_type change) std::cout << position[i] << ":" << change[i] << '\n'; } -int main(int argc, char const* argv[]) +int main(int argc, char const* argv[]) try { if(argc <= 2) { @@ -98,3 +99,9 @@ int main(int argc, char const* argv[]) return 0; } +catch(...) +{ + if(errno) + std::cout << "Oh nooo! " << std::strerror(errno) << '\n'; + throw; +} diff --git a/glue.cpp b/glue.cpp index dba6b41..a6bd8ca 100644 --- a/glue.cpp +++ b/glue.cpp @@ -1,4 +1,5 @@ #include <iostream> +#include <cstring> #include "simple/file.hpp" using namespace std; @@ -41,7 +42,7 @@ void process_input() glue(target); } -int main(int argc, char const * argv[]) +int main(int argc, char const * argv[]) try { if(argc < 2) process_input(); @@ -50,3 +51,9 @@ int main(int argc, char const * argv[]) return 0; } +catch(...) +{ + if(errno) + std::cout << "Oh nooo! " << std::strerror(errno) << '\n'; + throw; +} diff --git a/shred.cpp b/shred.cpp index 2a8febb..b2e08b1 100644 --- a/shred.cpp +++ b/shred.cpp @@ -5,6 +5,7 @@ #include <map> #include <functional> #include <algorithm> +#include <cstring> #include "simple/file.hpp" #include "simple/support/enum.hpp" @@ -135,7 +136,7 @@ void process_input() } } -int main(int argc, char const * argv[]) +int main(int argc, char const * argv[]) try { process_arguments( {argv, argv + argc} ); if(argc < 2) @@ -143,3 +144,9 @@ int main(int argc, char const * argv[]) return 0; } +catch(...) +{ + if(errno) + std::cout << "Oh nooo! " << std::strerror(errno) << '\n'; + throw; +} diff --git a/swap.cpp b/swap.cpp index 51341c8..98c9b29 100644 --- a/swap.cpp +++ b/swap.cpp @@ -1,4 +1,5 @@ #include <iostream> +#include <cstring> #include "simple/file.hpp" using namespace simple; @@ -16,7 +17,7 @@ void swap(const std::string& onePath, const std::string& otherPath) file::bwopex(otherPath) <<= one; } -int main(int argc, char const* argv[]) +int main(int argc, char const* argv[]) try { if(argc < 3) { @@ -31,3 +32,9 @@ int main(int argc, char const* argv[]) return 0; } +catch(...) +{ + if(errno) + std::cout << "Oh nooo! " << std::strerror(errno) << '\n'; + throw; +} -- GitLab