aboutsummaryrefslogtreecommitdiff
path: root/butl
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2016-10-21 17:17:00 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2016-10-21 17:17:00 +0300
commit070d99ca6d714e8789e67e2e797a1bf16ba35528 (patch)
treec01e620d8dc80b87031409494d97e897088f8623 /butl
parent31726418d0f8f77040aaa0f9f5d0c5bb36105b6f (diff)
Fix duplicated error description in exception thrown by fdstream
Diffstat (limited to 'butl')
-rw-r--r--butl/fdstream.cxx16
1 files 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<v, const char*>::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 <bool v>
static inline void
- throw_ios_failure (error_code, typename enable_if<!v, const char*>::type m)
+ throw_ios_failure (error_code ec,
+ typename enable_if<!v, const char*>::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<is_base_of<system_error, ios_base::failure>::value> (
- ec, m != nullptr ? m : ec.message ().c_str ());
+ ec, m);
}
// fdbuf