summaryrefslogtreecommitdiff
path: root/contrib/utility/Utility/ExH/Logic/DescriptiveException.ipp
blob: 4a50a68777758f96a823da09479f3b52c15a66fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// file      : Utility/ExH/Logic/DescriptiveException.ipp
// author    : Boris Kolpackov <boris@kolpackov.net>
// copyright : Copyright (c) 2002-2003 Boris Kolpackov
// license   : http://kolpackov.net/license.html

namespace Utility
{
  namespace ExH
  {
    namespace Logic
    {
      // c-tor's & d-tor

      inline DescriptiveException::
      DescriptiveException () throw ()
      {
      }

      inline DescriptiveException::
      DescriptiveException (char const* description) throw ()
      {
        init (description);
      }

      inline DescriptiveException::
      DescriptiveException (std::string const& description) throw ()
      {
        try
        {
          init (description.c_str ());
        }
        catch (...)
        {
        }
      }

      inline DescriptiveException::
      DescriptiveException (DescriptiveException const& src) throw ()
      {
        init (src.what ());
      }

      inline DescriptiveException::
      ~DescriptiveException () throw ()
      {
      }

      inline DescriptiveException& DescriptiveException::
      operator= (DescriptiveException const& src) throw ()
      {
        init (src.what ());
        return *this;
      }


      // accessors / modifiers

      inline void
      DescriptiveException::init (char const* description) throw ()
      {
        try
        {
          if (description == 0 || description[0] == '\0')
          {
            description_.reset (0);
          }
          else
          {
            if (description_.get () != 0)
            {
              *description_ = description;
            }
            else
            {
              description_.reset (new std::string (description));
            }
          }
        }
        catch (...)
        {
          description_.reset (0);
        }
      }

      inline char const*
      DescriptiveException::what () const throw ()
      {
        try
        {
          if (description_.get () != 0)
          {
            return description_->c_str ();
          }
        }
        catch (...)
        {
        }

        return Exception::what ();
      }
    }
  }
}
//$Id$