File indexing completed on 2024-04-21 15:23:40

0001 /********************************************************************************
0002  * Copyright (C) 2011-2015 by Stephen Allewell                                  *
0003  * steve.allewell@gmail.com                                                     *
0004  *                                                                              *
0005  * This program is free software; you can redistribute it and/or modify         *
0006  * it under the terms of the GNU General Public License as published by         *
0007  * the Free Software Foundation; either version 2 of the License, or            *
0008  * (at your option) any later version.                                          *
0009  ********************************************************************************/
0010 
0011 
0012 /**
0013  * @file
0014  * Implement the exception classes.
0015  */
0016 
0017 
0018 /**
0019  * @page exceptions Exceptions
0020  *
0021  * @section errors Errors
0022  * When handling data from various sources there is always the risk of encountering errors during
0023  * reading or writing that data. To avoid the problem of incomplete data being read or written
0024  * it is necessary to handle these errors to avoid later corruption of the data. Whilst this can
0025  * be done in different ways, SymbolEditor uses exceptions.
0026  *
0027  * @section exception_use Exception Use
0028  * Exceptions are used by enclosing operations that might cause errors in a try..catch block which
0029  * tries the operation and catches any exceptions that are thrown by those operations. This gives
0030  * the opportunity to do any cleaning up and displaying suitable error messages.
0031  */
0032 
0033 
0034 #include "Exceptions.h"
0035 
0036 #include <KLocalizedString>
0037 
0038 
0039 /**
0040  * Constructor
0041  */
0042 InvalidFile::InvalidFile()
0043 {
0044 }
0045 
0046 
0047 /**
0048  * Destructor
0049  */
0050 InvalidFile::~InvalidFile()
0051 {
0052 }
0053 
0054 
0055 /**
0056  * Constructor
0057  *
0058  * @param v the version of the file that was being read
0059  */
0060 InvalidFileVersion::InvalidFileVersion(qint32 v)
0061     :   version(v)
0062 {
0063 }
0064 
0065 
0066 /**
0067  * Destructor
0068  */
0069 InvalidFileVersion::~InvalidFileVersion()
0070 {
0071 }
0072 
0073 
0074 /**
0075  * Constructor
0076  *
0077  * @param status the status of the QDataStream that caused the exception
0078  */
0079 FailedReadLibrary::FailedReadLibrary(QDataStream::Status status)
0080     :   m_status(status)
0081 {
0082 }
0083 
0084 
0085 /**
0086  * Destructor
0087  */
0088 FailedReadLibrary::~FailedReadLibrary()
0089 {
0090 }
0091 
0092 
0093 /**
0094  * Get the status message of the QDataStream::Status
0095  *
0096  * @return a QString containing the stream status
0097  */
0098 QString FailedReadLibrary::statusMessage() const
0099 {
0100     if (m_status == QDataStream::ReadPastEnd) {
0101         return QString(i18n("Tried to read past the end of the data"));
0102     }
0103 
0104     if (m_status == QDataStream::ReadCorruptData) {
0105         return QString(i18n("Tried to read corrupted data"));
0106     }
0107 
0108     return QString(i18n("Undefined status message %1", m_status));
0109 }
0110 
0111 
0112 /**
0113  * Constructor
0114  *
0115  * @param status the status of the QDataStream that caused the exception
0116  */
0117 FailedWriteLibrary::FailedWriteLibrary(QDataStream::Status status)
0118     :   m_status(status)
0119 {
0120 }
0121 
0122 
0123 /**
0124  * Destructor
0125  */
0126 FailedWriteLibrary::~FailedWriteLibrary()
0127 {
0128 }
0129 
0130 
0131 /**
0132  * Get the status message of the QDataStream::Status
0133  *
0134  * @return a QString containing the stream status
0135  */
0136 QString FailedWriteLibrary::statusMessage() const
0137 {
0138 #if QT_VERSION >= 0x040800
0139 
0140     if (m_status == QDataStream::WriteFailed) {
0141         return QString(i18n("Failed to write to the device"));
0142     }
0143 
0144 #endif
0145 
0146     return QString(i18n("Undefined status message %1", m_status));
0147 }
0148 
0149 
0150 /**
0151  * Constructor
0152  *
0153  * @param v the version of the Symbol being read
0154  */
0155 InvalidSymbolVersion::InvalidSymbolVersion(qint32 v)
0156     :   version(v)
0157 {
0158 }
0159 
0160 
0161 /**
0162  * Destructor
0163  */
0164 InvalidSymbolVersion::~InvalidSymbolVersion()
0165 {
0166 }