File indexing completed on 2024-04-28 04:33:56

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  * @param v the version of the file that was being read
0043  */
0044 InvalidFileVersion::InvalidFileVersion(qint32 v)
0045     :   version(v)
0046 {
0047 }
0048 
0049 
0050 /**
0051  * Constructor
0052  *
0053  * @param status the status of the QDataStream that caused the exception
0054  */
0055 FailedReadLibrary::FailedReadLibrary(QDataStream::Status status)
0056     :   m_status(status)
0057 {
0058 }
0059 
0060 
0061 /**
0062  * Get the status message of the QDataStream::Status
0063  *
0064  * @return a QString containing the stream status
0065  */
0066 QString FailedReadLibrary::statusMessage() const
0067 {
0068     if (m_status == QDataStream::ReadPastEnd) {
0069         return QString(i18n("Tried to read past the end of the data"));
0070     }
0071 
0072     if (m_status == QDataStream::ReadCorruptData) {
0073         return QString(i18n("Tried to read corrupted data"));
0074     }
0075 
0076     return QString(i18n("Undefined status message %1", m_status));
0077 }
0078 
0079 
0080 /**
0081  * Constructor
0082  *
0083  * @param status the status of the QDataStream that caused the exception
0084  */
0085 FailedWriteLibrary::FailedWriteLibrary(QDataStream::Status status)
0086     :   m_status(status)
0087 {
0088 }
0089 
0090 
0091 /**
0092  * Get the status message of the QDataStream::Status
0093  *
0094  * @return a QString containing the stream status
0095  */
0096 QString FailedWriteLibrary::statusMessage() const
0097 {
0098 #if QT_VERSION >= 0x040800
0099 
0100     if (m_status == QDataStream::WriteFailed) {
0101         return QString(i18n("Failed to write to the device"));
0102     }
0103 
0104 #endif
0105 
0106     return QString(i18n("Undefined status message %1", m_status));
0107 }
0108 
0109 
0110 /**
0111  * Constructor
0112  *
0113  * @param v the version of the Symbol being read
0114  */
0115 InvalidSymbolVersion::InvalidSymbolVersion(qint32 v)
0116     :   version(v)
0117 {
0118 }