diff --git a/dbms/include/DB/Core/Exception.h b/dbms/include/DB/Core/Exception.h index 2acec282160..ccc87461335 100644 --- a/dbms/include/DB/Core/Exception.h +++ b/dbms/include/DB/Core/Exception.h @@ -38,4 +38,7 @@ using Poco::SharedPtr; typedef SharedPtr ExceptionPtr; typedef std::vector Exceptions; + +void throwFromErrno(const std::string & s, int code = 0); + } diff --git a/dbms/include/DB/IO/ReadBufferFromFileDescriptor.h b/dbms/include/DB/IO/ReadBufferFromFileDescriptor.h index 9b290f2b0e7..632a3eb9750 100644 --- a/dbms/include/DB/IO/ReadBufferFromFileDescriptor.h +++ b/dbms/include/DB/IO/ReadBufferFromFileDescriptor.h @@ -46,12 +46,6 @@ protected: return true; } - void throwFromErrno(const std::string & s, int code) - { - char buf[128]; - throw Exception(s + ", errno: " + Poco::NumberFormatter::format(errno) + ", strerror: " + std::string(strerror_r(errno, buf, sizeof(buf))), code); - } - /// Имя или описание файла virtual std::string getFileName() { diff --git a/dbms/include/DB/IO/WriteBufferFromFileDescriptor.h b/dbms/include/DB/IO/WriteBufferFromFileDescriptor.h index e150e254a25..8bead1cbebf 100644 --- a/dbms/include/DB/IO/WriteBufferFromFileDescriptor.h +++ b/dbms/include/DB/IO/WriteBufferFromFileDescriptor.h @@ -40,12 +40,6 @@ protected: } } - void throwFromErrno(const std::string & s, int code) - { - char buf[128]; - throw Exception(s + ", errno: " + Poco::NumberFormatter::format(errno) + ", strerror: " + std::string(strerror_r(errno, buf, sizeof(buf))), code); - } - /// Имя или описание файла virtual std::string getFileName() { diff --git a/dbms/src/Client/Client.cpp b/dbms/src/Client/Client.cpp index 17660a0c7a3..3540203bf63 100644 --- a/dbms/src/Client/Client.cpp +++ b/dbms/src/Client/Client.cpp @@ -57,13 +57,6 @@ namespace DB using Poco::SharedPtr; -void throwFromErrno(const std::string & s, int code) -{ - char buf[128]; - throw Exception(s + ", errno: " + Poco::NumberFormatter::format(errno) + ", strerror: " + std::string(strerror_r(errno, buf, sizeof(buf))), code); -} - - /** Пока существует объект этого класса - блокирует сигнал INT, при этом позволяет узнать, не пришёл ли он. * В один момент времени используйте только один экземпляр этого класса. */ diff --git a/dbms/src/Core/Exception.cpp b/dbms/src/Core/Exception.cpp index e42a1c3984e..af72fdbe27b 100644 --- a/dbms/src/Core/Exception.cpp +++ b/dbms/src/Core/Exception.cpp @@ -1,3 +1,8 @@ +#include +#include + +#include + #include @@ -39,4 +44,11 @@ void Exception::rethrow() const throw *this; } + +void throwFromErrno(const std::string & s, int code) +{ + char buf[128]; + throw Exception(s + ", errno: " + Poco::NumberFormatter::format(errno) + ", strerror: " + std::string(strerror_r(errno, buf, sizeof(buf))), code); +} + } diff --git a/utils/iotest/main.cpp b/utils/iotest/main.cpp index a57ada24019..8eeff43572e 100644 --- a/utils/iotest/main.cpp +++ b/utils/iotest/main.cpp @@ -12,10 +12,15 @@ #include #include +#include + #include #include +using DB::throwFromErrno; + + enum Mode { MODE_READ, @@ -26,14 +31,6 @@ enum Mode typedef Poco::SharedPtr ExceptionPtr; -void throwFromErrno(const std::string & s) -{ - char buf[128]; - throw Poco::Exception(s + ", errno: " + Poco::NumberFormatter::format(errno) - + ", strerror: " + std::string(strerror_r(errno, buf, sizeof(buf)))); -} - - void thread(int fd, Mode mode, size_t min_offset, size_t max_offset, size_t block_size, size_t count, ExceptionPtr & exception) { try