• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 DATASHARE_ERROR_H
17 #define DATASHARE_ERROR_H
18 
19 #include "datashare_js_utils.h"
20 
21 namespace OHOS {
22 namespace DataShare {
23 static const int EXCEPTION_PARAMETER_CHECK = 401;
24 static const int EXCEPTION_INNER = 15700000;
25 static const int EXCEPTION_HELPER_UNINITIALIZED = 15700010;
26 
27 class Error {
28 public:
~Error()29     virtual ~Error() {};
30     virtual std::string GetMessage() = 0;
31     virtual int GetCode() = 0;
32 };
33 
34 class ParametersTypeError : public Error {
35 public:
ParametersTypeError(const std::string & name,const std::string & wantType)36     ParametersTypeError(const std::string &name, const std::string &wantType) : name(name), wantType(wantType) {};
37     std::string GetMessage() override;
38     int GetCode() override;
39 private:
40     std::string name;
41     std::string wantType;
42 };
43 
44 class ParametersNumError : public Error {
45 public:
ParametersNumError(const std::string & wantNum)46     ParametersNumError(const std::string &wantNum) : wantNum(wantNum) {};
47     std::string GetMessage() override;
48     int GetCode() override;
49 private:
50     std::string wantNum;
51 };
52 
53 class DataShareHelperInitError : public Error {
54 public:
55     DataShareHelperInitError() = default;
56     std::string GetMessage() override;
57     int GetCode() override;
58 };
59 
60 class InnerError : public Error {
61 public:
62     InnerError() = default;
63     std::string GetMessage() override;
64     int GetCode() override;
65 };
66 } // namespace DataShare
67 } // namespace OHOS
68 
69 #endif // DATASHARE_ERROR_H