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