jsocketpp 1.0
A cross-platform C++20 socket library.
Loading...
Searching...
No Matches
jsocketpp::SocketException Class Reference

Represents socket-related errors in the jsocketpp library. More...

#include <SocketException.hpp>

Inheritance diagram for jsocketpp::SocketException:
Collaboration diagram for jsocketpp::SocketException:

Public Member Functions

 SocketException (const int code, const std::string &message="SocketException")
int getErrorCode () const noexcept
 ~SocketException () override=default

Private Attributes

int _errorCode

Detailed Description

Represents socket-related errors in the jsocketpp library.

SocketException is the standard exception type thrown by the jsocketpp socket library whenever a socket-related operation fails (such as connect, bind, send, or receive). It stores both an error code and a human-readable message describing the error.

The exception can be caught using a standard C++ try-catch block, making error handling robust and portable.

This exception inherits from std::runtime_error for compatibility with standard exception handling patterns and tools, and also from std::nested_exception to allow users to use std::throw_with_nested() for advanced error chaining.

Example: Catching and Handling Socket Exceptions

using namespace jsocketpp;
try {
Socket sock("example.com", 80);
sock.connect();
// ... other operations ...
} catch (const SocketException& ex) {
std::cerr << "Socket error (" << ex.code() << "): " << ex.what() << std::endl;
}
Exception class for socket-related errors in jsocketpp.
TCP client socket abstraction for jsocketpp.
Represents socket-related errors in the jsocketpp library.
Definition SocketException.hpp:58
TCP client connection abstraction (Java-like interface).
Definition Socket.hpp:91
A C++ socket library providing Java-style networking interfaces.
Definition BufferView.hpp:13
Note
This exception stores a copy of the error message and error code. It is not tied to any particular platform error format—use the code/message for display or logging.
jsocketpp itself does not throw nested exceptions, but this class enables developers using the library to opt into exception chaining if desired. This class is safe to use without exception chaining. If you don't need nested exceptions, simply construct and throw it normally.
Author
MangaD
Date
2025
Version
1.0

Constructor & Destructor Documentation

◆ SocketException()

jsocketpp::SocketException::SocketException ( const int code,
const std::string & message = "SocketException" )
inlineexplicit

◆ ~SocketException()

jsocketpp::SocketException::~SocketException ( )
overridedefault

Member Function Documentation

◆ getErrorCode()

int jsocketpp::SocketException::getErrorCode ( ) const
inlinenodiscardnoexcept

Member Data Documentation

◆ _errorCode

int jsocketpp::SocketException::_errorCode
private

The documentation for this class was generated from the following file: