Wallaroo  0.8
exceptions.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * wallaroo - A library for configurable creation and wiring of C++ classes.
3  * Copyright (C) 2012 Daniele Pallastrelli
4  *
5  * This file is part of wallaroo.
6  * For more information, see http://wallaroolib.sourceforge.net/
7  *
8  * Boost Software License - Version 1.0 - August 17th, 2003
9  *
10  * Permission is hereby granted, free of charge, to any person or organization
11  * obtaining a copy of the software and accompanying documentation covered by
12  * this license (the "Software") to use, reproduce, display, distribute,
13  * execute, and transmit the Software, and to prepare derivative works of the
14  * Software, and to permit third-parties to whom the Software is furnished to
15  * do so, all subject to the following:
16  *
17  * The copyright notices in the Software and this entire statement, including
18  * the above license grant, this restriction and the following disclaimer,
19  * must be included in all copies of the Software, in whole or in part, and
20  * all derivative works of the Software, unless such copies or derivative
21  * works are solely in the form of machine-executable object code generated by
22  * a source language processor.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
27  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
28  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
29  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30  * DEALINGS IN THE SOFTWARE.
31  ******************************************************************************/
32 
33 #ifndef WALLAROO_EXCEPTIONS_H_
34 #define WALLAROO_EXCEPTIONS_H_
35 
36 #include <stdexcept>
37 
38 namespace wallaroo
39 {
40 namespace detail
41 {
42  inline std::string FormatMsg(const std::string& msg, std::size_t line, std::size_t col)
43  {
44  std::ostringstream oss;
45  oss << "Line " << line << ", col " << col << ": " << msg;
46  return oss.str();
47  }
48 } // detail
49 
54 class WallarooError : public std::runtime_error
55 {
56 public:
60  WallarooError( const std::string &what ) :
61  std::runtime_error( what )
62  {
63  }
64 
65  ~WallarooError() throw()
66  {
67  }
68 };
69 
70 
75 {
76 public:
79  WallarooError( "The part has been deleted" )
80  {
81  }
82 
84  {
85  }
86 };
87 
88 
93 {
94 public:
97  WallarooError( "The catalog has not been specified. You must use a wallaroo_within section." )
98  {
99  }
100 
102  {
103  }
104 };
105 
106 
110 class WrongType : public WallarooError
111 {
112 public:
115  WallarooError( "The type is wrong for the cast." )
116  {
117  }
118 
119  ~WrongType() throw()
120  {
121  }
122 };
123 
124 
129 {
130 public:
132  ElementNotFound( const std::string& _element ) :
133  WallarooError( _element + " not found in the container" ),
134  element( _element )
135  {
136  }
138  {
139  }
140  const std::string& Element() const
141  {
142  return element;
143  }
144 private:
145  const std::string element;
146 };
147 
148 
153 {
154 public:
156  DuplicatedElement( const std::string& _element ) :
157  WallarooError( _element + " already in the container" ),
158  element( _element )
159  {
160  }
162  {
163  }
164  const std::string& Element() const
165  {
166  return element;
167  }
168 private:
169  const std::string element;
170 };
171 
172 
176 class WrongFile : public WallarooError
177 {
178 public:
180  explicit WrongFile( const std::string& msg ) :
181  WallarooError( msg )
182  {
183  }
184 
185  ~WrongFile() throw()
186  {
187  }
188 };
189 
194 {
195 public:
197  WiringError( const std::string& _element ) :
198  WallarooError( _element + " wiring error" ),
199  element( _element )
200  {
201  }
202  ~WiringError() throw()
203  {
204  }
205  const std::string& Element() const
206  {
207  return element;
208  }
209 private:
210  const std::string element;
211 };
212 
213 
218 {
219 public:
220  LexicalError(const std::string& msg, std::size_t line, std::size_t col) :
221  WallarooError(detail::FormatMsg(msg, line, col)) {}
222 };
223 
228 {
229 public:
231  SyntaxError(const std::string& msg, std::size_t line, std::size_t col) :
232  WallarooError(detail::FormatMsg(msg, line, col)) {}
233 };
234 
235 } // namespace
236 
237 #endif
std::string FormatMsg(const std::string &msg, std::size_t line, std::size_t col)
Definition: exceptions.h:42
WrongType()
Instantiate a WrongType.
Definition: exceptions.h:114
~CatalogNotSpecified()
Definition: exceptions.h:101
~WiringError()
Definition: exceptions.h:202
~WallarooError()
Definition: exceptions.h:65
const std::string & Element() const
Definition: exceptions.h:205
DeletedPartError()
Instantiate a DeletedPartError.
Definition: exceptions.h:78
~DuplicatedElement()
Definition: exceptions.h:161
Definition: exceptions.h:227
SyntaxError(const std::string &msg, std::size_t line, std::size_t col)
Instantiate a SyntaxError.
Definition: exceptions.h:231
Definition: exceptions.h:152
Definition: exceptions.h:217
Definition: exceptions.h:128
Definition: exceptions.h:92
WrongFile(const std::string &msg)
Instantiate a WrongFile.
Definition: exceptions.h:180
~ElementNotFound()
Definition: exceptions.h:137
const std::string & Element() const
Definition: exceptions.h:140
Definition: exceptions.h:74
ElementNotFound(const std::string &_element)
Instantiate a ElementNotFound.
Definition: exceptions.h:132
~WrongType()
Definition: exceptions.h:119
LexicalError(const std::string &msg, std::size_t line, std::size_t col)
Definition: exceptions.h:220
Definition: attribute.h:45
Definition: exceptions.h:193
WiringError(const std::string &_element)
Instantiate a WiringError.
Definition: exceptions.h:197
Definition: exceptions.h:54
~WrongFile()
Definition: exceptions.h:185
Definition: exceptions.h:176
Definition: exceptions.h:110
const std::string & Element() const
Definition: exceptions.h:164
~DeletedPartError()
Definition: exceptions.h:83
WallarooError(const std::string &what)
Definition: exceptions.h:60
CatalogNotSpecified()
Instantiate a CatalogNotSpecified.
Definition: exceptions.h:96
DuplicatedElement(const std::string &_element)
Instantiate a DuplicatedElement.
Definition: exceptions.h:156