File indexing completed on 2024-04-21 03:52:46

0001 /*
0002   This file is part of the kcalcore library.
0003 
0004   SPDX-FileCopyrightText: 2001-2003 Cornelius Schumacher <schumacher@kde.org>
0005 
0006   SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 /**
0009   @file
0010   This file is part of the API for handling calendar data and
0011   defines the Exception class.
0012 
0013   We don't use actual C++ exceptions right now. These classes are currently
0014   returned by an error function; but we can build upon them, if/when we start
0015   to use C++ exceptions.
0016 
0017   @brief
0018   Exception base class.
0019 
0020   @author Cornelius Schumacher \<schumacher@kde.org\>
0021 */
0022 
0023 #ifndef KCALCORE_EXCEPTIONS_H
0024 #define KCALCORE_EXCEPTIONS_H
0025 
0026 #include "kcalendarcore_export.h"
0027 
0028 #include <QString>
0029 #include <QStringList>
0030 
0031 #include <memory>
0032 
0033 namespace KCalendarCore
0034 {
0035 class ExceptionPrivate;
0036 
0037 /**
0038   Exception base class, currently used as a fancy kind of error code
0039   and not as an C++ exception.
0040 */
0041 class KCALENDARCORE_EXPORT Exception
0042 {
0043 public:
0044     /**
0045       The different types of error codes
0046     */
0047     enum ErrorCode {
0048         LoadError, /**< Load error */
0049         SaveError, /**< Save error */
0050         ParseErrorIcal, /**< Parse error in libical */
0051         ParseErrorKcal, /**< Parse error in libkcal */
0052         NoCalendar, /**< No calendar component found */
0053         CalVersion1, /**< vCalendar v1.0 detected */
0054         CalVersion2, /**< iCalendar v2.0 detected */
0055         CalVersionUnknown, /**< Unknown calendar format detected */
0056         Restriction, /**< Restriction violation */
0057         UserCancel, /**< User canceled the operation */
0058         NoWritableFound, /**< No writable resource is available */
0059         SaveErrorOpenFile,
0060         SaveErrorSaveFile,
0061         LibICalError,
0062         VersionPropertyMissing,
0063         ExpectedCalVersion2,
0064         ExpectedCalVersion2Unknown,
0065         ParseErrorNotIncidence,
0066         ParseErrorEmptyMessage,
0067         ParseErrorUnableToParse,
0068         ParseErrorMethodProperty,
0069     };
0070 
0071     /**
0072       Construct an exception.
0073       @param code is the error code.
0074       @param arguments is a list of arguments that can be passed
0075              to an i18n engine to help build a descriptive message for the user, a common
0076              argument is for example the filename where the error occurred.
0077     */
0078     explicit Exception(const ErrorCode code, const QStringList &arguments = QStringList());
0079 
0080     /**
0081       Destructor.
0082     */
0083     virtual ~Exception();
0084 
0085     /**
0086       Returns the error code.
0087       @return The ErrorCode for this exception.
0088     */
0089     Q_REQUIRED_RESULT virtual ErrorCode code() const;
0090 
0091     /**
0092       Returns the arguments.
0093       @return A QStringList with the argument list for this exception.
0094     */
0095     Q_REQUIRED_RESULT virtual QStringList arguments() const;
0096 
0097 private:
0098     std::unique_ptr<ExceptionPrivate> d;
0099 };
0100 
0101 } // namespace
0102 
0103 #endif