Exception: make source location print-out optional
[lttng-tools.git] / src / common / exception.cpp
index 028d253f2d885a6c9d9c29a4dc8c875a40b698f2..219e80fb18053ef8167e1d5d975f4f351f90370d 100644 (file)
 
 #include <sstream>
 
-namespace {
-std::string
-format_throw_location(const char *file_name, const char *function_name, unsigned int line_number)
-{
-       std::stringstream location;
-
-       location << "[" << function_name << "()"
-                << " " << file_name << ":" << line_number << "]";
-
-       return location.str();
-}
-} /* namespace */
-
 lttng::ctl::error::error(const std::string& msg,
                         lttng_error_code error_code,
-                        const char *file_name,
-                        const char *function_name,
-                        unsigned int line_number) :
-       runtime_error(msg + ": " + std::string(error_get_str(error_code)),
-                     file_name,
-                     function_name,
-                     line_number),
-       _error_code{ error_code }
+                        const lttng::source_location& location) :
+       runtime_error(msg, location), _error_code{ error_code }
 {
 }
 
 lttng::posix_error::posix_error(const std::string& msg,
-                               int errno_code,
-                               const char *file_name,
-                               const char *function_name,
-                               unsigned int line_number) :
-       std::system_error(errno_code,
-                         std::generic_category(),
-                         msg + " " + format_throw_location(file_name, function_name, line_number))
+                               unsigned int errno_code,
+                               const lttng::source_location& location) :
+       std::system_error(errno_code, std::generic_category()),
+       lttng::runtime_error(msg, location)
 {
 }
 
 lttng::runtime_error::runtime_error(const std::string& msg,
-                                   const char *file_name,
-                                   const char *function_name,
-                                   unsigned int line_number) :
-       std::runtime_error(msg + " " + format_throw_location(file_name, function_name, line_number))
+                                   const lttng::source_location& location) :
+       std::runtime_error(msg), source_location(location)
 {
 }
 
 lttng::unsupported_error::unsupported_error(const std::string& msg,
-                                           const char *file_name,
-                                           const char *function_name,
-                                           unsigned int line_number) :
-       std::runtime_error(msg + " " + format_throw_location(file_name, function_name, line_number))
+                                           const lttng::source_location& location) :
+       lttng::runtime_error(msg, location)
 {
 }
 
 lttng::communication_error::communication_error(const std::string& msg,
-                                               const char *file_name,
-                                               const char *function_name,
-                                               unsigned int line_number) :
-       runtime_error(msg, file_name, function_name, line_number)
+                                               const lttng::source_location& location) :
+       runtime_error(msg, location)
 {
 }
 
 lttng::protocol_error::protocol_error(const std::string& msg,
-                                     const char *file_name,
-                                     const char *function_name,
-                                     unsigned int line_number) :
-       communication_error(msg, file_name, function_name, line_number)
+                                     const lttng::source_location& location) :
+       communication_error(msg, location)
 {
 }
 
 lttng::invalid_argument_error::invalid_argument_error(const std::string& msg,
-                                                     const char *file_name,
-                                                     const char *function_name,
-                                                     unsigned int line_number) :
-       runtime_error(msg, file_name, function_name, line_number)
+                                                     const lttng::source_location& location) :
+       runtime_error(msg, location)
 {
 }
This page took 0.023448 seconds and 4 git commands to generate.