0.4.3
ALSON::CommonException类 参考

#include <CommonException.h>

Public 成员函数

 CommonException (uint64_t code, const std::string &message, uint64_t line=0, const std::string &filename="")
 
 CommonException (CommonException &cause, uint64_t code, const std::string &message, uint64_t line=0, const std::string &filename="")
 
 CommonException (std::exception &cause, uint64_t code, const std::string &message, uint64_t line=0, const std::string &filename="")
 
 ~CommonException () override=default
 
 CommonException (const CommonException &)=default
 
CommonExceptionoperator= (const CommonException &)=default
 
 CommonException (CommonException &&) noexcept=default
 
CommonExceptionoperator= (CommonException &&) noexcept=default
 
std::string getStackTrace () const
 
uint64_t getCode () const
 
std::string getMessage () const
 
char const * what () const ALS_EXCEPTION_NOEXCEPT override
 

详细描述

通用异常

大部分 API 接口都可能会抛出异常,异常类型要么是 CommonException,要么是 CommonException 的子类。 我们应该捕获异常,并采取合适的逻辑处理异常,如下示例展示了如何捕获并处理异常。

try {
// do something
}
catch (ALSON::CommonException& cause) {
std::cout << cause.getStackTrace() << std::endl;
if (cause.getCode() == 999999) {
// do something
}
else if (cause.getCode() == 152006) {
// do something
}
else {
// do something
}
}
std::string getStackTrace() const
uint64_t getCode() const
自从
0.4.0

在文件 CommonException.h71 行定义.

构造及析构函数说明

◆ CommonException() [1/5]

ALSON::CommonException::CommonException ( uint64_t code,
const std::string & message,
uint64_t line = 0,
const std::string & filename = "" )

◆ CommonException() [2/5]

ALSON::CommonException::CommonException ( CommonException & cause,
uint64_t code,
const std::string & message,
uint64_t line = 0,
const std::string & filename = "" )

◆ CommonException() [3/5]

ALSON::CommonException::CommonException ( std::exception & cause,
uint64_t code,
const std::string & message,
uint64_t line = 0,
const std::string & filename = "" )

◆ ~CommonException()

ALSON::CommonException::~CommonException ( )
overridedefault

◆ CommonException() [4/5]

ALSON::CommonException::CommonException ( const CommonException & )
default

◆ CommonException() [5/5]

ALSON::CommonException::CommonException ( CommonException && )
defaultnoexcept

成员函数说明

◆ operator=() [1/2]

CommonException & ALSON::CommonException::operator= ( const CommonException & )
default

◆ operator=() [2/2]

CommonException & ALSON::CommonException::operator= ( CommonException && )
defaultnoexcept

◆ getStackTrace()

std::string ALSON::CommonException::getStackTrace ( ) const

获取一个由异常堆栈组成的字符串

返回
一个由异常堆栈组成的字符串

◆ getCode()

uint64_t ALSON::CommonException::getCode ( ) const

获取当前异常的异常码

返回
当前异常的异常码

◆ getMessage()

std::string ALSON::CommonException::getMessage ( ) const

获取当前异常的详细信息

返回
当前异常的详细信息

◆ what()

char const * ALSON::CommonException::what ( ) const
override

获取当前异常的详细信息

作用等同于 getMessage 函数,为兼容 std::exception 而设置

返回
当前异常的详细信息
My Custom Doxygen Footer
Data Processing Programmer's Guide 0.4.3
Copyright © 2014-2024 Henan Alson Intelligent Technology Co, Ltd 河南埃尔森智能科技有限公司 版权所有 豫ICP备15002212号