curl_exception: implement exception class to throw libcurl errors

This commit is contained in:
Syping 2026-04-05 00:09:18 +02:00
parent ce6b3785ac
commit 8de0473669
3 changed files with 74 additions and 1 deletions

View file

@ -0,0 +1,30 @@
/*****************************************************************************
* dtranslatebot Discord Translate Bot
* Copyright (C) 2026 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* This software is provided as-is, no warranties are given to you, we are not
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#include "curl_exception.h"
using namespace bot::exception;
curl_exception::curl_exception(const std::string &message, CURLcode error_code) : m_message(message), m_error_code(error_code) {
}
curl_exception::~curl_exception() noexcept {
}
const char* curl_exception::what() const noexcept {
return m_message.c_str();
}

41
src/core/curl_exception.h Normal file
View file

@ -0,0 +1,41 @@
/*****************************************************************************
* dtranslatebot Discord Translate Bot
* Copyright (C) 2026 Syping
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* This software is provided as-is, no warranties are given to you, we are not
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
#ifndef CURL_EXCEPTION_H
#define CURL_EXCEPTION_H
#include <curl/curl.h>
#include <exception>
#include <string>
namespace bot {
namespace exception {
class curl_exception : public std::exception {
public:
explicit curl_exception(const std::string &message, CURLcode error_code);
virtual ~curl_exception() noexcept;
const char* what() const noexcept override;
private:
const std::string m_message;
const CURLcode m_error_code;
};
}
};
#endif // CURL_EXCEPTION_H