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 
34 class Mutex;
35 
36 class Exception : public std::exception {
37  public:
38 
39  Exception(const char *format, ...) throw();
40  Exception(int errno, const char *format, ...) throw();
41  Exception(const Exception &exc) throw();
42  virtual ~Exception() throw();
43 
44  virtual void raise();
45  void prepend(const char *format, ...) throw();
46  void append(const char *format, ...) throw();
47  void append_va(const char *format, va_list va) throw();
48  void append(const Exception &e) throw();
49  void print_trace() throw();
50  void print_backtrace() const throw();
51  char * generate_backtrace() const throw();
52 
53  int get_errno() throw();
54 
55  void set_type_id(const char *id);
56  const char * type_id() const;
57 
58  virtual const char* what() const throw();
59 
60  Exception& operator=(const Exception &exc) throw();
61 
62  protected:
63  /** Internal exception message list */
64  struct message_list_t {
65  message_list_t *next; /**< pointer to next element, NULL if last element */
66  char *msg; /**< pointer to message, may not be NULL, will be freed
67  * in dtor */
68  };
69 
70  public:
71  class iterator
72  {
73  friend class Exception;
74  private:
75  iterator(message_list_t *message_list);
76  public:
77  iterator(const iterator &i);
78  iterator();
79 
80  iterator & operator++ (); // prefix
81  iterator operator++ (int inc); // postfix
82 
83  bool operator== (const iterator & i) const;
84  bool operator!= (const iterator & i) const;
85 
86  const char * operator* () const;
87  iterator & operator= (const iterator & i);
88 
89  private:
90  message_list_t *mlist;
91  };
92 
93  iterator begin() throw();
94  iterator end() throw();
95 
96  protected:
97  Exception() throw();
98 
99  void append_nolock(const char *format, ...) throw();
100  void append_nolock_va(const char *format, va_list va) throw();
101  void append_nolock_nocopy(char *msg) throw();
102  void prepend_nolock_va(const char *format, va_list va) throw();
103  void copy_messages(const Exception &exc) throw();
104 
109 
110  int _errno;
111 
112  private:
113  const char *__type_id;
114 };
115 
116 
117 } // end namespace fawkes
118 
119 #endif
message_list_t * messages_end
Pointer that points to the very last message.
Definition: exception.h:107
Mutex * messages_mutex
Mutex to protect operations on messages list.
Definition: exception.h:108
int get_errno()
Get errno.
Definition: exception.cpp:643
Fawkes library namespace.
Exception()
Constructor for subclasses.
Definition: exception.cpp:257
int _errno
Error number, should be used if the error was caused by a method that supplies errno.
Definition: exception.h:110
void prepend_nolock_va(const char *format, va_list va)
Prepend messages without lock by formatted string.
Definition: exception.cpp:429
Message iterator for exceptions.
Definition: exception.h:71
virtual ~Exception()
Destructor.
Definition: exception.cpp:269
iterator()
Plain constructor.
Definition: exception.cpp:715
iterator end()
Get end iterator for messages.
Definition: exception.cpp:695
char * generate_backtrace() const
Generate backtrace string.
Definition: exception.cpp:586
virtual const char * what() const
Get primary string.
Definition: exception.cpp:661
iterator & operator++()
Prefix ++ operator.
Definition: exception.cpp:734
Base class for exceptions in Fawkes.
Definition: exception.h:36
void append_nolock_va(const char *format, va_list va)
Append messages without lock by formatted string.
Definition: exception.cpp:460
void append_nolock(const char *format,...)
Append messages without lock.
Definition: exception.cpp:392
void print_backtrace() const
Prints a backtrace.
Definition: exception.cpp:563
const char * type_id() const
Get type ID.
Definition: exception.cpp:311
message_list_t * messages
List of messages.
Definition: exception.h:105
void prepend(const char *format,...)
Prepend messages to the message list.
Definition: exception.cpp:322
message_list_t * messages_iterator
Iterator to iterate over messages.
Definition: exception.h:106
const char * operator*() const
Get current message.
Definition: exception.cpp:785
iterator begin()
Get iterator for messages.
Definition: exception.cpp:678
void append_va(const char *format, va_list va)
Append messages to the message list.
Definition: exception.cpp:361
Internal exception message list.
Definition: exception.h:64
void print_trace()
Prints trace to stderr.
Definition: exception.cpp:619
iterator & operator=(const iterator &i)
Assignment operator.
Definition: exception.cpp:800
bool operator==(const iterator &i) const
Check equality.
Definition: exception.cpp:763
void set_type_id(const char *id)
Set exception type ID.
Definition: exception.cpp:292
message_list_t * next
pointer to next element, NULL if last element
Definition: exception.h:65
void copy_messages(const Exception &exc)
Copy messages from given exception.
Definition: exception.cpp:533
Exception & operator=(const Exception &exc)
Assign an Exception.
Definition: exception.cpp:519
Mutex mutual exclusion lock.
Definition: mutex.h:32
bool operator!=(const iterator &i) const
Check inequality.
Definition: exception.cpp:774
void append_nolock_nocopy(char *msg)
Append message without copying.
Definition: exception.cpp:491
void append(const char *format,...)
Append messages to the message list.
Definition: exception.cpp:341
char * msg
pointer to message, may not be NULL, will be freed in dtor
Definition: exception.h:66