Fawkes API  Fawkes Development Version
exception.h
1 
2 /***************************************************************************
3  * exception.h - basic exception
4  *
5  * Generated: Thu Feb 09 13:02:37 2006 (from FireVision)
6  * Copyright 2005-2006 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef _CORE_EXCEPTION_H_
25 #define _CORE_EXCEPTION_H_
26 
27 // needed for va_list
28 #include <cstdarg>
29 #include <exception>
30 
31 namespace fawkes {
32 
33 class Mutex;
34 
35 class Exception : public std::exception
36 {
37 public:
38  Exception(const char *format, ...) throw();
39  Exception(int errnoval, const char *format, ...) throw();
40  Exception(const Exception &exc) throw();
41  virtual ~Exception() throw();
42 
43  virtual void raise();
44  void prepend(const char *format, ...) throw();
45  void append(const char *format, ...) throw();
46  void append_va(const char *format, va_list va) throw();
47  void append(const Exception &e) throw();
48  void print_trace() throw();
49  void print_backtrace() const throw();
50  char * generate_backtrace() const throw();
51 
52  int get_errno() throw();
53 
54  void set_type_id(const char *id);
55  const char *type_id() const;
56 
57  virtual const char *what() const throw();
58  virtual const char *what_no_backtrace() const throw();
59 
60  Exception &operator=(const Exception &exc) throw();
61 
62 protected:
63  /** Internal exception message list */
64  struct message_list_t
65  {
66  message_list_t *next; /**< pointer to next element, NULL if last element */
67  char * msg; /**< pointer to message, may not be NULL, will be freed
68  * in dtor */
69  };
70 
71 public:
72  class iterator
73  {
74  friend Exception;
75 
76  private:
77  iterator(message_list_t *message_list);
78 
79  public:
80  iterator(const iterator &i);
81  iterator();
82 
83  iterator &operator++(); // prefix
84  iterator operator++(int inc); // postfix
85 
86  bool operator==(const iterator &i) const;
87  bool operator!=(const iterator &i) const;
88 
89  const char *operator*() const;
90  iterator & operator=(const iterator &i);
91 
92  private:
93  message_list_t *mlist;
94  };
95 
96  iterator begin() throw();
97  iterator end() throw();
98 
99 protected:
100  Exception() throw();
101 
102  void append_nolock(const char *format, ...) throw();
103  void append_nolock_va(const char *format, va_list va) throw();
104  void append_nolock_nocopy(char *msg) throw();
105  void prepend_nolock_va(const char *format, va_list va) throw();
106  void copy_messages(const Exception &exc) throw();
107 
112 
113  int _errno;
114 
115 private:
116  const char *type_id_;
117 };
118 
119 } // end namespace fawkes
120 
121 #endif
fawkes::Exception::append_nolock_nocopy
void append_nolock_nocopy(char *msg)
Append message without copying.
Definition: exception.cpp:479
fawkes::Exception::print_backtrace
void print_backtrace() const
Prints a backtrace.
Definition: exception.cpp:547
fawkes::Exception::iterator::operator++
iterator & operator++()
Prefix ++ operator.
Definition: exception.cpp:727
fawkes::Exception::append_va
void append_va(const char *format, va_list va)
Append messages to the message list.
Definition: exception.cpp:353
fawkes::Exception::end
iterator end()
Get end iterator for messages.
Definition: exception.cpp:692
fawkes::Mutex
Definition: mutex.h:38
fawkes::Exception::messages_end
message_list_t * messages_end
Definition: exception.h:116
fawkes::Exception::Exception
Exception()
Constructor for subclasses.
Definition: exception.cpp:253
fawkes::Exception::messages
message_list_t * messages
Definition: exception.h:114
fawkes::Exception::iterator::iterator
iterator()
Plain constructor.
Definition: exception.cpp:710
fawkes::Exception::append_nolock
void append_nolock(const char *format,...)
Append messages without lock.
Definition: exception.cpp:383
fawkes::Exception::type_id
const char * type_id() const
Get type ID.
Definition: exception.cpp:304
fawkes::Exception::iterator::operator==
bool operator==(const iterator &i) const
Check equality.
Definition: exception.cpp:754
fawkes::Exception::raise
virtual void raise()
This can be used to throw this exception.
Definition: exception.cpp:540
fawkes::Exception::append
void append(const char *format,...)
Append messages to the message list.
Definition: exception.cpp:333
fawkes::Exception::iterator::operator*
const char * operator*() const
Get current message.
Definition: exception.cpp:773
fawkes::Exception::get_errno
int get_errno()
Get errno.
Definition: exception.cpp:622
fawkes
fawkes::Exception::message_list_t
Internal exception message list.
Definition: exception.h:70
fawkes::Exception::print_trace
void print_trace()
Prints trace to stderr.
Definition: exception.cpp:601
fawkes::Exception::begin
iterator begin()
Get iterator for messages.
Definition: exception.cpp:676
fawkes::Exception::copy_messages
void copy_messages(const Exception &exc)
Copy messages from given exception.
Definition: exception.cpp:519
fawkes::Exception::what_no_backtrace
virtual const char * what_no_backtrace() const
Get primary string (does not implicitly print the back trace).
Definition: exception.cpp:663
fawkes::Exception::messages_iterator
message_list_t * messages_iterator
Definition: exception.h:115
fawkes::Exception::prepend_nolock_va
void prepend_nolock_va(const char *format, va_list va)
Prepend messages without lock by formatted string.
Definition: exception.cpp:419
fawkes::Exception::what
virtual const char * what() const
Get primary string.
Definition: exception.cpp:639
fawkes::Exception::iterator::operator!=
bool operator!=(const iterator &i) const
Check inequality.
Definition: exception.cpp:764
fawkes::Exception::iterator::operator=
iterator & operator=(const iterator &i)
Assignment operator.
Definition: exception.cpp:787
fawkes::Exception::generate_backtrace
char * generate_backtrace() const
Generate backtrace string.
Definition: exception.cpp:569
fawkes::Exception::prepend
void prepend(const char *format,...)
Prepend messages to the message list.
Definition: exception.cpp:314
fawkes::Exception::set_type_id
void set_type_id(const char *id)
Set exception type ID.
Definition: exception.cpp:286
fawkes::Exception::messages_mutex
Mutex * messages_mutex
Definition: exception.h:117
fawkes::Exception::iterator
Definition: exception.h:78
fawkes::Exception::_errno
int _errno
Definition: exception.h:119
fawkes::Exception::append_nolock_va
void append_nolock_va(const char *format, va_list va)
Append messages without lock by formatted string.
Definition: exception.cpp:449
fawkes::Exception
Definition: exception.h:41