1 /* 2 * Copyright (c) 2022 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 OBJECT_ERROR_H 17 #define OBJECT_ERROR_H 18 19 #include <string> 20 21 namespace OHOS { 22 namespace ObjectStore { 23 static constexpr int EXCEPTION_INNER = 0; 24 25 class Error { 26 public: ~Error()27 virtual ~Error(){}; 28 virtual std::string GetMessage() = 0; 29 virtual int GetCode() = 0; 30 }; 31 32 class ParametersType : public Error { 33 public: ParametersType(const std::string & name,const std::string & wantType)34 ParametersType(const std::string &name, const std::string &wantType) : name(name), wantType(wantType){}; 35 std::string GetMessage() override; 36 int GetCode() override; 37 38 private: 39 std::string name; 40 std::string wantType; 41 }; 42 43 class ParametersNum : public Error { 44 public: ParametersNum(const std::string & wantNum)45 ParametersNum(const std::string &wantNum) : wantNum(wantNum){}; 46 std::string GetMessage() override; 47 int GetCode() override; 48 49 private: 50 std::string wantNum; 51 }; 52 53 class PermissionError : public Error { 54 public: 55 PermissionError() = default; 56 std::string GetMessage() override; 57 int GetCode() override; 58 }; 59 60 class DatabaseError : public Error { 61 public: 62 DatabaseError() = default; 63 std::string GetMessage() override; 64 int GetCode() override; 65 }; 66 67 class InnerError : public Error { 68 public: 69 InnerError() = default; 70 std::string GetMessage() override; 71 int GetCode() override; 72 }; 73 74 class DeviceNotSupportedError : public Error { 75 public: 76 DeviceNotSupportedError() = default; 77 std::string GetMessage() override; 78 int GetCode() override; 79 }; 80 } // namespace ObjectStore 81 } // namespace OHOS 82 83 #endif // OBJECT_ERROR_H