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 FILEMGMT_LIBN_N_ERROR_H 17 #define FILEMGMT_LIBN_N_ERROR_H 18 19 #include <functional> 20 #include <string> 21 #include <tuple> 22 23 #include "n_napi.h" 24 25 namespace OHOS { 26 namespace FileManagement { 27 namespace LibN { 28 constexpr int ERRNO_NOERR = 0; 29 30 class NError { 31 public: 32 NError(); 33 NError(int ePosix); 34 NError(std::function<std::tuple<uint32_t, std::string>()> errGen); 35 ~NError() = default; 36 37 explicit operator bool() const; 38 39 napi_value GetNapiErr(napi_env env); 40 41 void ThrowErr(napi_env env); 42 void ThrowErr(napi_env env, std::string errMsg); 43 44 private: 45 int errno_ = ERRNO_NOERR; 46 std::string errMsg_; 47 }; 48 } // namespace LibN 49 } // namespace FileManagement 50 } // namespace OHOS 51 52 #endif // FILEMGMT_LIBN_N_ERROR_H