From 070d99ca6d714e8789e67e2e797a1bf16ba35528 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 21 Oct 2016 17:17:00 +0300 Subject: Fix duplicated error description in exception thrown by fdstream --- butl/fdstream.cxx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/butl/fdstream.cxx b/butl/fdstream.cxx index 8e6f6c9..109b041 100644 --- a/butl/fdstream.cxx +++ b/butl/fdstream.cxx @@ -42,14 +42,22 @@ namespace butl static inline void throw_ios_failure (error_code e, typename enable_if::type m) { - throw ios_base::failure (m, e); + // The idea here is to make an error code to be saved into failure + // exception and to make a string returned by what() to contain the error + // description plus an optional custom message if provided. Unfortunatelly + // there is no way to say that the custom message is absent. Passing an + // empty string results for GCC (as of version 5.3.1) with a description + // like this (note the ugly ": " prefix): ": No such file or directory". + // + throw ios_base::failure (m != nullptr ? m : "", e); } template static inline void - throw_ios_failure (error_code, typename enable_if::type m) + throw_ios_failure (error_code ec, + typename enable_if::type m) { - throw ios_base::failure (m); + throw ios_base::failure (m != nullptr ? m : ec.message ().c_str ()); } inline void @@ -57,7 +65,7 @@ namespace butl { error_code ec (ev, system_category ()); throw_ios_failure::value> ( - ec, m != nullptr ? m : ec.message ().c_str ()); + ec, m); } // fdbuf -- cgit v1.1