annotate base/Exceptions.cpp @ 1848:98339fac0faf

Avoid returning expired pointers
author Chris Cannam
date Thu, 23 Apr 2020 15:39:08 +0100
parents cc27f35aa75c
children
rev   line source
Chris@130 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@130 2
Chris@130 3 /*
Chris@130 4 Sonic Visualiser
Chris@130 5 An audio file viewer and annotation editor.
Chris@130 6 Centre for Digital Music, Queen Mary, University of London.
Chris@130 7 This file copyright 2006 Chris Cannam.
Chris@130 8
Chris@130 9 This program is free software; you can redistribute it and/or
Chris@130 10 modify it under the terms of the GNU General Public License as
Chris@130 11 published by the Free Software Foundation; either version 2 of the
Chris@130 12 License, or (at your option) any later version. See the file
Chris@130 13 COPYING included with this distribution for more information.
Chris@130 14 */
Chris@130 15
Chris@130 16 #include "Exceptions.h"
Chris@130 17
Chris@130 18 #include <iostream>
Chris@130 19
Chris@843 20 #include "Debug.h"
Chris@843 21
Chris@130 22 FileNotFound::FileNotFound(QString file) throw() :
Chris@130 23 m_file(file)
Chris@130 24 {
Chris@1848 25 cerr << "ERROR: File not found: " << file << endl;
Chris@130 26 }
Chris@130 27
Chris@130 28 const char *
Chris@130 29 FileNotFound::what() const throw()
Chris@130 30 {
Chris@1848 31 static QByteArray msg;
Chris@1848 32 msg = QString("File \"%1\" not found").arg(m_file).toLocal8Bit();
Chris@1848 33 return msg.data();
Chris@130 34 }
Chris@130 35
Chris@130 36 FailedToOpenFile::FailedToOpenFile(QString file) throw() :
Chris@130 37 m_file(file)
Chris@130 38 {
Chris@843 39 cerr << "ERROR: Failed to open file: "
Chris@843 40 << file << endl;
Chris@130 41 }
Chris@130 42
Chris@130 43 const char *
Chris@130 44 FailedToOpenFile::what() const throw()
Chris@130 45 {
Chris@1848 46 static QByteArray msg;
Chris@1848 47 msg = QString("Failed to open file \"%1\"").arg(m_file).toLocal8Bit();
Chris@1848 48 return msg.data();
Chris@130 49 }
Chris@130 50
Chris@130 51 DirectoryCreationFailed::DirectoryCreationFailed(QString directory) throw() :
Chris@130 52 m_directory(directory)
Chris@130 53 {
Chris@843 54 cerr << "ERROR: Directory creation failed for directory: "
Chris@1848 55 << directory << endl;
Chris@130 56 }
Chris@130 57
Chris@130 58 const char *
Chris@130 59 DirectoryCreationFailed::what() const throw()
Chris@130 60 {
Chris@1848 61 static QByteArray msg;
Chris@1848 62 msg = QString("Directory creation failed for \"%1\"").arg(m_directory)
Chris@1848 63 .toLocal8Bit();
Chris@1848 64 return msg.data();
Chris@130 65 }
Chris@130 66
Chris@130 67 FileReadFailed::FileReadFailed(QString file) throw() :
Chris@130 68 m_file(file)
Chris@130 69 {
Chris@1848 70 cerr << "ERROR: File read failed for file: " << file << endl;
Chris@130 71 }
Chris@130 72
Chris@130 73 const char *
Chris@130 74 FileReadFailed::what() const throw()
Chris@130 75 {
Chris@1848 76 static QByteArray msg;
Chris@1848 77 msg = QString("File read failed for \"%1\"").arg(m_file).toLocal8Bit();
Chris@1848 78 return msg.data();
Chris@130 79 }
Chris@130 80
Chris@130 81 FileOperationFailed::FileOperationFailed(QString file, QString op) throw() :
Chris@130 82 m_file(file),
Chris@130 83 m_operation(op)
Chris@130 84 {
Chris@1848 85 cerr << "ERROR: File " << op << " failed for file: " << file << endl;
Chris@130 86 }
Chris@130 87
Chris@130 88 const char *
Chris@130 89 FileOperationFailed::what() const throw()
Chris@130 90 {
Chris@1848 91 static QByteArray msg;
Chris@1848 92 msg = QString("File %1 failed for \"%2\"").arg(m_operation).arg(m_file)
Chris@1848 93 .toLocal8Bit();
Chris@1848 94 return msg.data();
Chris@130 95 }
Chris@130 96
Chris@130 97 InsufficientDiscSpace::InsufficientDiscSpace(QString directory,
Chris@1038 98 size_t required,
Chris@1038 99 size_t available) throw() :
Chris@130 100 m_directory(directory),
Chris@130 101 m_required(required),
Chris@130 102 m_available(available)
Chris@130 103 {
Chris@843 104 cerr << "ERROR: Not enough disc space available in "
Chris@1848 105 << directory << ": need " << required
Chris@1848 106 << ", only have " << available << endl;
Chris@130 107 }
Chris@130 108
Chris@544 109 InsufficientDiscSpace::InsufficientDiscSpace(QString directory) throw() :
Chris@544 110 m_directory(directory),
Chris@544 111 m_required(0),
Chris@544 112 m_available(0)
Chris@544 113 {
Chris@1848 114 cerr << "ERROR: Not enough disc space available in " << directory << endl;
Chris@544 115 }
Chris@544 116
Chris@130 117 const char *
Chris@130 118 InsufficientDiscSpace::what() const throw()
Chris@130 119 {
Chris@1848 120 static QByteArray msg;
Chris@544 121 if (m_required > 0) {
Chris@1848 122 msg = QString("Not enough space available in \"%1\": need %2, have %3")
Chris@1848 123 .arg(m_directory).arg(m_required).arg(m_available).toLocal8Bit();
Chris@544 124 } else {
Chris@1848 125 msg = QString("Not enough space available in \"%1\"")
Chris@1848 126 .arg(m_directory).toLocal8Bit();
Chris@544 127 }
Chris@1848 128 return msg.data();
Chris@130 129 }
Chris@130 130
Chris@387 131 AllocationFailed::AllocationFailed(QString purpose) throw() :
Chris@387 132 m_purpose(purpose)
Chris@387 133 {
Chris@1848 134 cerr << "ERROR: Allocation failed: " << purpose << endl;
Chris@387 135 }
Chris@387 136
Chris@387 137 const char *
Chris@387 138 AllocationFailed::what() const throw()
Chris@387 139 {
Chris@1848 140 static QByteArray msg;
Chris@1848 141 msg = QString("Allocation failed: %1").arg(m_purpose).toLocal8Bit();
Chris@1848 142 return msg.data();
Chris@387 143 }
Chris@387 144
Chris@387 145