카테고리 없음
[C ++] QT에서 내 자신의 예외를 생성하고 함수에서 예외를 던지기
행복을전해요
2021. 2. 18. 14:58
거의 완료되었습니다. A의 throw
성명, 일반적 예외 클래스의 임시 객체를 던져. 예
void Command(QString Command_in)
{
if(Command_in != "some string")
{
throw MyException{};
}
}
기술적으로는 객체 이름을 지정하는 데 아무런 문제가 없지만 한 줄 더 길고 더 읽기 어렵습니다.
void Command(QString Command_in)
{
if(Command_in != "some string")
{
MyException someRandomName;
throw someRandomName;
}
}
물론 이것은 방법이 필요하지 않다는 것을 의미 raise()
합니다. 그러나 원하는 경우 실제로 다음과 같아야합니다 static
.
class MyException: public QtConcurrent::Exception
{
public:
static void raise() const {qDebug() << "\nException: "; throw MyException{};}
};
출처
https://stackoverflow.com/questions/22079861