1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ROSEN_MODULES_TEXGINE_SRC_TEXGINE_EXCEPTION_H 17 #define ROSEN_MODULES_TEXGINE_SRC_TEXGINE_EXCEPTION_H 18 19 #include <string> 20 21 namespace OHOS { 22 namespace Rosen { 23 namespace TextEngine { 24 #define TEXGINE_EXCEPTION(name) te##name 25 26 #define EXCEPTION_LIST(MACRO) \ 27 MACRO(INVALID_ARGUMENT, "Invalid Argument") \ 28 MACRO(API_FAILED, "API Failed") \ 29 MACRO(ERROR_STATUS, "Error Status") \ 30 MACRO(OUT_OF_RANGE, "Out Of Range") \ 31 MACRO(INVALID_CHAR_GROUPS, "Invalid CharGroups") \ 32 MACRO(NULLPTR, "Null Pointer") 33 34 enum class ExceptionType { 35 CUSTOM = -1, 36 SUCCESS, 37 #define DEFINE_ENUM_MACRO(name, str) name, 38 EXCEPTION_LIST(DEFINE_ENUM_MACRO) 39 #undef DEFINE_ENUM_MACRO 40 }; 41 42 struct TexgineException { 43 ExceptionType code = ExceptionType::CUSTOM; 44 std::string message = ""; 45 }; 46 47 #define DEFINE_CONSTVAR_MACRO(name, str) \ 48 static inline const TexgineException TEXGINE_EXCEPTION(name) = {.code = ExceptionType::name, .message = str}; 49 EXCEPTION_LIST(DEFINE_CONSTVAR_MACRO); 50 #undef DEFINE_CONSTVAR_MACRO 51 #undef EXCEPTION_LIST 52 53 TexgineException CustomException(const char *msg); 54 TexgineException APIFailedException(const char *msg); 55 } // namespace TextEngine 56 } // namespace Rosen 57 } // namespace OHOS 58 59 #endif // ROSEN_MODULES_TEXGINE_SRC_TEXGINE_EXCEPTION_H 60