Open Chinese Convert
1.0.3
A project for conversion between Traditional and Simplified Chinese
|
00001 /* 00002 * Open Chinese Convert 00003 * 00004 * Copyright 2010-2014 BYVoid <byvoid@byvoid.com> 00005 * 00006 * Licensed under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 00019 #pragma once 00020 00021 #include <sstream> 00022 #include <stdexcept> 00023 #include <string> 00024 00025 #include "Export.hpp" 00026 00027 #ifdef _MSC_VER 00028 00029 // Until Visual Studio 2013 (12.0), C++ 11 "noexcept" qualifier is not supported 00030 #define noexcept 00031 #endif // ifdef _MSC_VER 00032 00033 namespace opencc { 00034 00035 class OPENCC_EXPORT Exception : public std::exception { 00036 public: 00037 Exception() {} 00038 00039 virtual ~Exception() throw() {} 00040 00041 Exception(const std::string& _message) : message(_message) {} 00042 00043 virtual const char* what() const noexcept { return message.c_str(); } 00044 00045 protected: 00046 std::string message; 00047 }; 00048 00049 class OPENCC_EXPORT FileNotFound : public Exception { 00050 public: 00051 FileNotFound(const std::string& fileName) 00052 : Exception(fileName + " not found or not accessible.") {} 00053 }; 00054 00055 class OPENCC_EXPORT FileNotWritable : public Exception { 00056 public: 00057 FileNotWritable(const std::string& fileName) 00058 : Exception(fileName + " not writable.") {} 00059 }; 00060 00061 class OPENCC_EXPORT InvalidFormat : public Exception { 00062 public: 00063 InvalidFormat(const std::string& message) 00064 : Exception("Invalid format: " + message) {} 00065 }; 00066 00067 class OPENCC_EXPORT InvalidTextDictionary : public InvalidFormat { 00068 public: 00069 InvalidTextDictionary(const std::string& _message, size_t lineNum) 00070 : InvalidFormat("") { 00071 std::ostringstream buffer; 00072 buffer << "Invalid text dictionary at line " << lineNum << ": " << _message; 00073 message = buffer.str(); 00074 } 00075 }; 00076 00077 class OPENCC_EXPORT InvalidUTF8 : public Exception { 00078 public: 00079 InvalidUTF8(const std::string& _message) 00080 : Exception("Invalid UTF8: " + _message) {} 00081 }; 00082 00083 class OPENCC_EXPORT ShouldNotBeHere : public Exception { 00084 public: 00085 ShouldNotBeHere() : Exception("ShouldNotBeHere! This must be a bug.") {} 00086 }; 00087 00088 } // namespace opencc