Used a more uniform of logging and added a commandline parser.
[UnsignedByte.git] / src / Resource / Exceptions.h
blob4c3a5b2ce3afda9f469707dc9fa508a6be0a1d12
1 /***************************************************************************
2 * Copyright (C) 2008 by Sverre Rabbelier *
3 * sverre@rabbelier.nl *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #pragma once
23 /**
24 * @file Exceptions.h
25 * This file contains the custom exceptions used.
27 * @see ExcecutionException
28 * @see SavableLocked
29 * @see RowNotFoundException
30 * @see SqliteError
31 */
33 #include "Types.h"
35 /**
36 * This exception is thrown when an exception occured as the result of a user command.
37 */
38 class ExcecutionException : public std::runtime_error
40 public:
41 /** Constructs a new ExcecutionException. */
42 ExcecutionException(std::exception& e, value_type accountid, cstring line);
44 ~ExcecutionException() throw () { }
46 const char* what() const throw() { return m_msg.c_str(); }
48 private:
49 std::exception& m_exception;
50 std::string m_msg;
51 value_type m_accountid;
52 std::string m_line;
55 /**
56 * This exception is thrown when a savable was already locked while trying to perform an operation that needs the ock.
57 */
58 class SavableLocked : public std::runtime_error
60 public:
61 /** Construct a new SavableLocked exception. */
62 SavableLocked() : std::runtime_error("Savable was already locked.") { }
65 /**
66 * This exception is thrown when no row was found as the result of an SQL query.
67 */
68 class RowNotFoundException : public std::runtime_error
70 public:
71 /** Construct a new RowNotFoundException with the specified message. */
72 RowNotFoundException(const std::string& arg) : std::runtime_error(arg) { }
75 /**
76 * This exception is thrown when an error occured as the result of an SQL query.
77 */
78 class SqliteError : public std::runtime_error
80 public:
81 /** Construct a new SqliteError from the specified database. */
82 SqliteError(sqlite3*);
84 /** Construct a new SqliteError from the specified database. */
85 SqliteError(sqlite3*, const std::string& sql);
87 /** Destructor, a noop. */
88 ~SqliteError() throw() { }
90 const char* what() const throw();
92 private:
93 int m_sqliteErrno; /**< The number of the error. */
94 const char* m_sqliteError; /**< The message of the error. */
95 std::string m_msg; /**< The compiled message. */