Athena IO Library
FileNotFoundException.hpp
1 // This file is part of libAthena.
2 //
3 // libAthena is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // libAthena is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with libAthena. If not, see <http://www.gnu.org/licenses/>
15 
16 #ifndef FILENOTFOUNDEXCEPTION_HPP
17 #define FILENOTFOUNDEXCEPTION_HPP
18 
19 #include "Athena/Exception.hpp"
20 
21 namespace Athena
22 {
23 namespace error
24 {
34 {
35 public:
39  inline FileNotFoundException(const std::string& filename, const std::string& file, const std::string& function, const int line) :
40  Exception(std::string("FileNotFoundException: Could not find file \"") + filename + std::string("\", please check that it exists."), file, function, line),
41  m_filename(filename)
42  {
43  m_exceptionName = "FileNotFoundException";
44  }
45 
49  inline std::string filename() const { return m_filename; }
50 private:
51  std::string m_filename;
52 };
53 } // error
54 } // Athena
55 
56 #ifndef THROW_FILE_NOT_FOUND_EXCEPTION
57 #define THROW_FILE_NOT_FOUND_EXCEPTION(msg) \
58  do { \
59  if (atGetExceptionHandler()) \
60  { \
61  atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, msg); \
62  return; \
63  } \
64  else \
65  throw Athena::error::FileNotFoundException(msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \
66 } while(0)
67 #endif
68 
69 #ifndef THROW_FILE_NOT_FOUND_EXCEPTION_RETURN
70 #define THROW_FILE_NOT_FOUND_EXCEPTION_RETURN(ret, msg) \
71  do { \
72  if (atGetExceptionHandler()) \
73  { \
74  atGetExceptionHandler()(__FILE__, AT_PRETTY_FUNCTION, __LINE__, msg); \
75  return ret; \
76  } \
77  else \
78  throw Athena::error::FileNotFoundException(msg, __FILE__, AT_PRETTY_FUNCTION, __LINE__); \
79 } while(0)
80 #endif
81 
82 
83 #endif // FILENOTFOUNDEXCEPTION_HPP
FileNotFoundException(const std::string &filename, const std::string &file, const std::string &function, const int line)
The constructor for an FileNotFoundException.
std::string filename() const
Returns the path of the offending file.
An excpeption thrown when a file could not be found at the given path.
The baseclass for all Exceptions.
Definition: Exception.hpp:38