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 const int EXCEPTION_DEVICE_NOT_SUPPORT = 801;
24 static const int EXCEPTION_PARAMETER_CHECK = 401;
25 static const int EXCEPTION_NO_PERMISSION = 201;
26 static const int EXCEPTION_DB_EXIST = 15400001;
27 static const int EXCEPTION_INNER = 0;
28 
29 class Error {
30 public:
~Error()31     virtual ~Error(){};
32     virtual std::string GetMessage() = 0;
33     virtual int GetCode() = 0;
34 };
35 
36 class ParametersType : public Error {
37 public:
ParametersType(const std::string & name,const std::string & wantType)38     ParametersType(const std::string &name, const std::string &wantType) : name(name), wantType(wantType){};
39     std::string GetMessage() override;
40     int GetCode() override;
41 
42 private:
43     std::string name;
44     std::string wantType;
45 };
46 
47 class ParametersNum : public Error {
48 public:
ParametersNum(const std::string & wantNum)49     ParametersNum(const std::string &wantNum) : wantNum(wantNum){};
50     std::string GetMessage() override;
51     int GetCode() override;
52 
53 private:
54     std::string wantNum;
55 };
56 
57 class PermissionError : public Error {
58 public:
59     PermissionError() = default;
60     std::string GetMessage() override;
61     int GetCode() override;
62 };
63 
64 class DatabaseError : public Error {
65 public:
66     DatabaseError() = default;
67     std::string GetMessage() override;
68     int GetCode() override;
69 };
70 
71 class InnerError : public Error {
72 public:
73     InnerError() = default;
74     std::string GetMessage() override;
75     int GetCode() override;
76 };
77 
78 class DeviceNotSupportedError : public Error {
79 public:
80     DeviceNotSupportedError() = default;
81     std::string GetMessage() override;
82     int GetCode() override;
83 };
84 } // namespace ObjectStore
85 } // namespace OHOS
86 
87 #endif // OBJECT_ERROR_H