MyGUI 3.5.3
MyGUI_Exception.cpp
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#include "MyGUI_Precompiled.h"
8#include "MyGUI_Exception.h"
9#include "MyGUI_Diagnostic.h"
10#include "MyGUI_StringUtility.h"
11
12#include <utility>
13
14namespace MyGUI
15{
16
17 void detail::throwBadCast(std::string_view _from, std::string_view _to, const char* _file, int _line)
18 {
19 std::ostringstream stream;
20 stream << "Cannot cast from type '" << _from << "' to type '" << _to << "'.";
21 std::string message = stream.str();
22 LogManager::getInstance().log(MYGUI_LOG_SECTION, LogLevel::Critical, message, _file, _line);
23 message += '\n';
24 throw Exception(std::move(message), "MyGUI", _file, _line);
25 }
26
27 Exception::Exception(std::string _description, std::string _source, std::string _file, long _line) :
28 mDescription(std::move(_description)),
29 mSource(std::move(_source)),
30 mFile(std::move(_file)),
31 mLine(_line)
32 {
33 }
34
35 const std::string& Exception::getFullDescription() const
36 {
37 if (mFullDesc.empty())
38 {
39 if (mLine > 0)
40 {
41 mFullDesc = utility::toString(
42 "MyGUI EXCEPTION : ",
43 mDescription,
44 " in ",
45 mSource,
46 " at ",
47 mFile,
48 " (line ",
49 mLine,
50 ")");
51 }
52 else
53 {
54 mFullDesc = utility::toString("MyGUI EXCEPTION : ", mDescription, " in ", mSource);
55 }
56 }
57
58 return mFullDesc;
59 }
60
61 const std::string& Exception::getSource() const
62 {
63 return mSource;
64 }
65
66 const std::string& Exception::getFile() const
67 {
68 return mFile;
69 }
70
71 long Exception::getLine() const
72 {
73 return mLine;
74 }
75
76 const std::string& Exception::getDescription() const
77 {
78 return mDescription;
79 }
80
81 // Override std::exception::what
82 const char* Exception::what() const noexcept
83 {
84 return getFullDescription().c_str();
85 }
86
87} // namespace MyGUI
#define MYGUI_LOG_SECTION