Open Chinese Convert 1.1.9
A project for conversion between Traditional and Simplified Chinese
Loading...
Searching...
No Matches
Exception.hpp
1/*
2 * Open Chinese Convert
3 *
4 * Copyright 2010-2014 Carbo Kuo <byvoid@byvoid.com>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#pragma once
20
21#include <sstream>
22#include <stdexcept>
23#include <string>
24
25#include "Export.hpp"
26
27#if defined(_MSC_VER) && _MSC_VER < 1900
28// Before Visual Studio 2015 (14.0), C++ 11 "noexcept" qualifier is not
29// supported
30#define noexcept
31#endif // ifdef _MSC_VER
32
33namespace opencc {
34
35class OPENCC_EXPORT Exception {
36public:
37 Exception() {}
38
39 virtual ~Exception() throw() {}
40
41 Exception(const std::string& _message) : message(_message) {}
42
43 virtual const char* what() const noexcept { return message.c_str(); }
44
45protected:
46 std::string message;
47};
48
49class OPENCC_EXPORT FileNotFound : public Exception {
50public:
51 FileNotFound(const std::string& fileName)
52 : Exception(fileName + " not found or not accessible.") {}
53};
54
55class OPENCC_EXPORT FileNotWritable : public Exception {
56public:
57 FileNotWritable(const std::string& fileName)
58 : Exception(fileName + " not writable.") {}
59};
60
61class OPENCC_EXPORT InvalidFormat : public Exception {
62public:
63 InvalidFormat(const std::string& message)
64 : Exception("Invalid format: " + message) {}
65};
66
67class OPENCC_EXPORT InvalidTextDictionary : public InvalidFormat {
68public:
69 InvalidTextDictionary(const std::string& _message, size_t lineNum)
70 : InvalidFormat("") {
71 std::ostringstream buffer;
72 buffer << "Invalid text dictionary at line " << lineNum << ": " << _message;
73 message = buffer.str();
74 }
75};
76
77class OPENCC_EXPORT InvalidUTF8 : public Exception {
78public:
79 InvalidUTF8(const std::string& _message)
80 : Exception("Invalid UTF8: " + _message) {}
81};
82
83class OPENCC_EXPORT ShouldNotBeHere : public Exception {
84public:
85 ShouldNotBeHere() : Exception("ShouldNotBeHere! This must be a bug.") {}
86};
87
88} // namespace opencc
Definition Exception.hpp:35
Definition Exception.hpp:49
Definition Exception.hpp:55
Definition Exception.hpp:61
Definition Exception.hpp:67
Definition Exception.hpp:77
Definition Exception.hpp:83