fix typo
[platform/upstream/libzypp.git] / zypp / base / Exception.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/Exception.cc
10  *
11 */
12 #include <iostream>
13
14 #include "zypp/base/Logger.h"
15 #include "zypp/base/String.h"
16 #include "zypp/base/Exception.h"
17
18 using std::endl;
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23   ///////////////////////////////////////////////////////////////////
24   namespace exception_detail
25   { /////////////////////////////////////////////////////////////////
26
27     std::string CodeLocation::asString() const
28     {
29       return str::form( "%s(%s):%u",
30                         _file.c_str(),
31                         _func.c_str(),
32                         _line );
33     }
34
35     std::ostream & operator<<( std::ostream & str, const CodeLocation & obj )
36     { return str << obj.asString(); }
37
38     /////////////////////////////////////////////////////////////////
39   } // namespace exception_detail
40   ///////////////////////////////////////////////////////////////////
41
42   Exception::Exception( const CodeLocation & where_r, const std::string & msg_r )
43   : _where( where_r ), _msg( msg_r )
44   {}
45
46   Exception::~Exception() throw()
47   {}
48
49   std::string Exception::asString() const
50   {
51     std::string ret( _where.asString() );
52     ret += ": ";
53     return ret += _msg;
54   }
55
56   std::string Exception::strErrno( int errno_r )
57   {
58     return str::strerror( errno_r );
59   }
60
61   std::string Exception::strErrno( int errno_r, const std::string & msg_r )
62   {
63     std::string ret( msg_r );
64     ret += ": ";
65     return ret += strErrno( errno_r );
66   }
67
68   void Exception::relocate( Exception & excpt_r, const CodeLocation & where_r )
69   {
70     excpt_r._where = where_r;
71   }
72
73   void Exception::log( const Exception & excpt_r, const CodeLocation & where_r,
74                        const char *const prefix_r )
75   {
76     INT << where_r << " " << prefix_r << " " << excpt_r << endl;
77   }
78
79   std::ostream & operator<<( std::ostream & str, const Exception & obj )
80   { return str << obj.asString(); }
81
82   /////////////////////////////////////////////////////////////////
83 } // namespace zypp
84 ///////////////////////////////////////////////////////////////////