File indexing completed on 2024-04-28 04:32:00

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  * @file
0013  * Implement the exception classes.
0014  */
0015 
0016 /**
0017  * @page exceptions Exceptions
0018  *
0019  * @section errors Errors
0020  * When handling data from various sources there is always the risk of encountering errors during
0021  * reading or writing that data. To avoid the problem of incomplete data being read or written
0022  * it is necessary to handle these errors to avoid later corruption of the data. Whilst this can
0023  * be done in different ways, SymbolEditor uses exceptions.
0024  *
0025  * @section exception_use Exception Use
0026  * Exceptions are used by enclosing operations that might cause errors in a try..catch block which
0027  * tries the operation and catches any exceptions that are thrown by those operations. This gives
0028  * the opportunity to do any cleaning up and displaying suitable error messages.
0029  */
0030 
0031 #include "Exceptions.h"
0032 
0033 #include <KLocalizedString>
0034 
0035 /**
0036  * Constructor
0037  */
0038 InvalidFile::InvalidFile()
0039 {
0040 }
0041 
0042 /**
0043  * Constructor
0044  *
0045  * @param v the version of the file that was being read
0046  */
0047 InvalidFileVersion::InvalidFileVersion(const QString &v)
0048     : version(v)
0049 {
0050 }
0051 
0052 /**
0053  * Constructor
0054  *
0055  * @param s the status of the QDataStream that caused the exception
0056  */
0057 FailedReadFile::FailedReadFile(QDataStream::Status s)
0058 {
0059     if (s == QDataStream::ReadPastEnd) {
0060         status = QString(i18n("Tried to read past the end of the data"));
0061     } else if (s == QDataStream::ReadCorruptData) {
0062         status = QString(i18n("Tried to read corrupted data"));
0063     } else {
0064         status = QString(i18n("Undefined status message status %1", s));
0065     }
0066 }
0067 
0068 /**
0069  * Constructor
0070  *
0071  * @param s the status message for the event causing the error
0072  */
0073 FailedReadFile::FailedReadFile(const QString &s)
0074     : status(s)
0075 {
0076 }
0077 
0078 /**
0079  * Constructor
0080  *
0081  * @param status the status of the QDataStream that caused the exception
0082  */
0083 FailedWriteFile::FailedWriteFile(QDataStream::Status status)
0084     : m_status(status)
0085 {
0086 }
0087 
0088 /**
0089  * Get the status message of the QDataStream::Status
0090  *
0091  * @return a QString containing the stream status
0092  */
0093 QString FailedWriteFile::statusMessage() const
0094 {
0095 #if QT_VERSION >= 0x040800
0096 
0097     if (m_status == QDataStream::WriteFailed) {
0098         return QString(i18n("Failed to write to the device"));
0099     }
0100 
0101 #endif
0102 
0103     return QString(i18n("Undefined status message status %1", m_status));
0104 }
0105 
0106 /**
0107  * Constructor
0108  *
0109  * @param v the version of the Symbol being read
0110  */
0111 InvalidSymbolVersion::InvalidSymbolVersion(qint32 v)
0112     : version(v)
0113 {
0114 }