Open Chinese Convert 1.0.1 A project for conversion between Traditional and Simplified Chinese

- Main Page
- Modules
- Classes
- Examples

All Classes Functions Typedefs Modules
Exception.hpp
1 /*
2 * Open Chinese Convert
3 *
4 * Copyright 2010-2014 BYVoid <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 #ifdef _MSC_VER
28
29 // Until Visual Studio 2013 (12.0), C++ 11 "noexcept" qualifier is not supported
30 # define noexcept
31 #endif // ifdef _MSC_VER
32
33 namespace opencc {
34 class OPENCC_EXPORT Exception : public std::exception {
35 public:
36 Exception() {
37 }
38
39 virtual ~Exception() throw() {
40 }
41
42 Exception(const std::string& _message) : message(_message) {
43 }
44
45 virtual const char* what() const noexcept {
46 return message.c_str();
47 }
48
49 protected:
50 std::string message;
51 };
52
53 class OPENCC_EXPORT FileNotFound : public Exception {
54 public:
55 FileNotFound(const std::string& fileName) :
56 Exception(fileName + " not found or not accessible.") {
57 }
58 };
59
60 class OPENCC_EXPORT FileNotWritable : public Exception {
61 public:
62 FileNotWritable(const std::string& fileName) :
63 Exception(fileName + " not writable.") {
64 }
65 };
66
67 class OPENCC_EXPORT InvalidFormat : public Exception {
68 public:
69 InvalidFormat(const std::string& message) :
70 Exception("Invalid format: " + message) {
71 }
72 };
73
74 class OPENCC_EXPORT InvalidTextDictionary : public InvalidFormat {
75 public:
76 InvalidTextDictionary(const std::string& _message, size_t lineNum) :
77 InvalidFormat("") {
78 std::ostringstream buffer;
79 buffer << "Invalid text dictionary at line " << lineNum << ": "
80 << _message;
81 message = buffer.str();
82 }
83 };
84
85 class OPENCC_EXPORT InvalidUTF8 : public Exception {
86 public:
87 InvalidUTF8(const std::string& _message) :
88 Exception("Invalid UTF8: " + _message) {
89 }
90 };
91 }
opencc::Exception
Definition: Exception.hpp:34
opencc::InvalidUTF8
Definition: Exception.hpp:85
opencc::FileNotFound
Definition: Exception.hpp:53
opencc::InvalidFormat
Definition: Exception.hpp:67
opencc
Definition: BinaryDict.hpp:24
opencc::InvalidTextDictionary
Definition: Exception.hpp:74
opencc::FileNotWritable
Definition: Exception.hpp:60