File indexing completed on 2024-04-28 16:01:32
0001 /****************************************************************************** 0002 * This file is part of the libqgit2 library 0003 * Copyright (c) 2011 Laszlo Papp <djszapi@archlinux.us> 0004 * Copyright (C) 2013 Leonardo Giordani 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Lesser General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2.1 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Lesser General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Lesser General Public 0017 * License along with this library; if not, write to the Free Software 0018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0019 */ 0020 0021 #ifndef LIBQGIT2_EXCEPTION_H 0022 #define LIBQGIT2_EXCEPTION_H 0023 0024 #include <exception> 0025 #include "libqgit2_export.h" 0026 #include <QtCore/QByteArray> 0027 0028 namespace LibQGit2 0029 { 0030 /** 0031 * @brief Exception class to throw Git exceptions. 0032 * 0033 * @ingroup LibQGit2 0034 * @{ 0035 */ 0036 class LIBQGIT2_EXPORT Exception : public std::exception 0037 { 0038 public: 0039 /** 0040 * A category for an exception. 0041 * 0042 * @note These map directly to libgit2 error codes. 0043 * @see https://libgit2.github.com/libgit2/#v0.21.0/type/git_error_t 0044 */ 0045 enum Category { 0046 None, 0047 NoMemory, 0048 OS, 0049 Invalid, 0050 Reference, 0051 ZLib, 0052 Repository, 0053 Config, 0054 RegEx, 0055 ODB, 0056 Index, 0057 Object, 0058 Net, 0059 Tag, 0060 Tree, 0061 Indexer, 0062 SSL, 0063 Submodule, 0064 Thread, 0065 Stash, 0066 Checkout, 0067 FetchHead, 0068 Merge, 0069 SSH, 0070 Filter, 0071 Revert, 0072 Callback, 0073 Cherrypick 0074 }; 0075 0076 Exception(); 0077 Exception(const QString& msg, Category category = None); 0078 ~Exception() throw(); 0079 0080 const char *what() const throw(); 0081 0082 QByteArray message() const throw(); 0083 0084 Category category() const throw(); 0085 0086 private: 0087 QByteArray m_msg; 0088 Category m_category; 0089 }; 0090 0091 inline int qGitThrow(int ret) { if (ret < 0) throw Exception(); return ret; } 0092 0093 inline void qGitEnsureValue(int value, int ret) { if (qGitThrow(ret) != value) throw Exception(); } 0094 0095 /**@}*/ 0096 } 0097 0098 #endif // LIBQGIT2_EXCEPTION_H