enable easy switching between 0.22 and svn opensync sources
[barry.git] / opensync-plugin / src / error.h
bloba58ea1a73b6f73b62fb182a641507501920a7dca
1 ///
2 /// \file error.h
3 /// Exception classes used specifically by the plugin.
4 ///
6 /*
7 Copyright (C) 2006-2007, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_SYNC_ERROR_H__
23 #define __BARRY_SYNC_ERROR_H__
25 #include <stdexcept>
26 #include <opensync/opensync.h>
28 //////////////////////////////////////////////////////////////////////////////
29 // osync_error exception class
31 /// Exception class for wrapping OSyncError messages. Takes ownership
32 /// of the error, and unref's it on destruction.
33 class osync_error : public std::runtime_error
35 OSyncError *m_error;
37 public:
38 explicit osync_error(OSyncError *error)
39 : std::runtime_error(get_error_msg(error)),
40 m_error(error)
44 // For osync errors that have no error object
45 explicit osync_error(const char *msg)
46 : std::runtime_error(msg),
47 m_error(0)
51 // handle copying correctly
52 osync_error(const osync_error &other)
53 : std::runtime_error(other.what()),
54 m_error(0)
56 operator=(other);
59 osync_error& operator=(const osync_error &other);
60 ~osync_error() throw();
62 OSyncError* c_obj() { return m_error; }
64 static std::string get_error_msg(OSyncError *error);
68 //////////////////////////////////////////////////////////////////////////////
69 // ConvertError exception class
71 class ConvertError : public std::runtime_error
73 public:
74 ConvertError(const std::string &msg) : std::runtime_error(msg) {}
78 #endif