C++ APISession methods
set_exception_callback
Registers a callback for exceptional receive-path failures surfaced as std::exception_ptr.
set_exception_callback installs a hook for exceptional receive-path failures
that are surfaced as std::exception_ptr.
Function variants
void set_exception_callback(std::function<void(std::exception_ptr)> callback);Runs on the library I/O thread
Do not call synchronous blaze::session methods from this callback. If you
need to continue work from here, stay on async API or hand control back to
your own thread/executor.
Callback signature
void(std::exception_ptr eptr)Prop
Type
Behavior notes
- This callback is intended for exceptional conditions, not ordinary API failures.
- Normal API statuses such as
blaze::status::not_authorizedorblaze::status::license_not_founddo not go here. - Normal per-operation transport failures are still returned through the callback/result of the method that triggered them.
- This hook is useful when the library encounters a receive-path problem that becomes a
std::system_error, for example invalid incoming protocol/message data. - In those cases, the library invokes this callback and then shuts the session down.
- Pass
nullptror an emptystd::functionto clear the callback.
Inspecting the exception
If eptr is not null, rethrow it to inspect the underlying exception:
try {
std::rethrow_exception(eptr);
} catch (const std::system_error& e) {
// inspect e.code()
} catch (const std::exception& e) {
// inspect e.what()
}Example
Compilation note
This example compiles in the same form from C++14 to C++26.
#include "blazeauth/api/api.hpp"
#include <exception>
#include <iostream>
#include <system_error>
int main() {
blaze::session session;
session.set_exception_callback([](std::exception_ptr eptr) {
if (!eptr) {
return;
}
try {
std::rethrow_exception(eptr);
} catch (const std::system_error& e) {
std::cout << "Library exception: " << e.code().message() << '\n';
} catch (const std::exception& e) {
std::cout << "Library exception: " << e.what() << '\n';
}
});
return 0;
}