1cb7eb8c9Sopenharmony_ci/* 2cb7eb8c9Sopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3cb7eb8c9Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4cb7eb8c9Sopenharmony_ci * you may not use this file except in compliance with the License. 5cb7eb8c9Sopenharmony_ci * You may obtain a copy of the License at 6cb7eb8c9Sopenharmony_ci * 7cb7eb8c9Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8cb7eb8c9Sopenharmony_ci * 9cb7eb8c9Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10cb7eb8c9Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11cb7eb8c9Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12cb7eb8c9Sopenharmony_ci * See the License for the specific language governing permissions and 13cb7eb8c9Sopenharmony_ci * limitations under the License. 14cb7eb8c9Sopenharmony_ci */ 15cb7eb8c9Sopenharmony_ci 16cb7eb8c9Sopenharmony_ci#ifndef DFSU_EXCEPTION_H 17cb7eb8c9Sopenharmony_ci#define DFSU_EXCEPTION_H 18cb7eb8c9Sopenharmony_ci 19cb7eb8c9Sopenharmony_ci#include <exception> 20cb7eb8c9Sopenharmony_ci#include <sstream> 21cb7eb8c9Sopenharmony_ci#include <string> 22cb7eb8c9Sopenharmony_ci 23cb7eb8c9Sopenharmony_ci#include "utils_log.h" 24cb7eb8c9Sopenharmony_ci 25cb7eb8c9Sopenharmony_cinamespace OHOS { 26cb7eb8c9Sopenharmony_cinamespace Storage { 27cb7eb8c9Sopenharmony_cinamespace DistributedFile { 28cb7eb8c9Sopenharmony_cienum { 29cb7eb8c9Sopenharmony_ci ERR_DEFAULT, 30cb7eb8c9Sopenharmony_ci ERR_UTILS_ACTOR_QUEUE_STOP, 31cb7eb8c9Sopenharmony_ci ERR_UTILS_ACTOR_INVALID_CMD, 32cb7eb8c9Sopenharmony_ci ERR_NETWORK_AGENT_TEMPLATE_OPEN_SESSION_FAIL, 33cb7eb8c9Sopenharmony_ci ERR_SOFTBUS_AGENT_ON_SESSION_OPENED_FAIL, 34cb7eb8c9Sopenharmony_ci ERR_DEVICE_CID_UN_INIT, 35cb7eb8c9Sopenharmony_ci ERR_DEVICE_EXTRADATA_UN_INIT, 36cb7eb8c9Sopenharmony_ci ERR_CONNECT_LINK_TYPE 37cb7eb8c9Sopenharmony_ci}; 38cb7eb8c9Sopenharmony_ci 39cb7eb8c9Sopenharmony_ciclass DfsuException : public std::exception { 40cb7eb8c9Sopenharmony_cipublic: 41cb7eb8c9Sopenharmony_ci DfsuException(int code, const std::string &msg) : code_(code), msg_(msg) {}; 42cb7eb8c9Sopenharmony_ci 43cb7eb8c9Sopenharmony_ci uint32_t code() const noexcept 44cb7eb8c9Sopenharmony_ci { 45cb7eb8c9Sopenharmony_ci return code_; 46cb7eb8c9Sopenharmony_ci } 47cb7eb8c9Sopenharmony_ci 48cb7eb8c9Sopenharmony_ci virtual const char *what() const noexcept 49cb7eb8c9Sopenharmony_ci { 50cb7eb8c9Sopenharmony_ci return msg_.c_str(); 51cb7eb8c9Sopenharmony_ci } 52cb7eb8c9Sopenharmony_ci 53cb7eb8c9Sopenharmony_ciprivate: 54cb7eb8c9Sopenharmony_ci int code_ {ERR_DEFAULT}; 55cb7eb8c9Sopenharmony_ci std::string msg_; 56cb7eb8c9Sopenharmony_ci}; 57cb7eb8c9Sopenharmony_ci 58cb7eb8c9Sopenharmony_ci#define ThrowException(code, msg) \ 59cb7eb8c9Sopenharmony_ci do { \ 60cb7eb8c9Sopenharmony_ci std::stringstream __ss; \ 61cb7eb8c9Sopenharmony_ci __ss << '[' << (code) << ']' << (msg) << std::endl; \ 62cb7eb8c9Sopenharmony_ci LOGE("%{public}s", __ss.str().c_str()); \ 63cb7eb8c9Sopenharmony_ci throw DfsuException((code), __ss.str()); \ 64cb7eb8c9Sopenharmony_ci } while (0) 65cb7eb8c9Sopenharmony_ci} // namespace DistributedFile 66cb7eb8c9Sopenharmony_ci} // namespace Storage 67cb7eb8c9Sopenharmony_ci} // namespace OHOS 68cb7eb8c9Sopenharmony_ci#endif // DFSU_EXCEPTION_H