Ice 3.8
C++ API Reference
Loading...
Searching...
No Matches
Exception.h
1// Copyright (c) ZeroC, Inc.
2
3#ifndef ICE_EXCEPTION_H
4#define ICE_EXCEPTION_H
5
6#include "Config.h"
7
8#include <exception>
9#include <ostream>
10
11namespace Ice
12{
13 /// Abstract base class for all Ice exceptions. It has only two derived classes: LocalException and UserException.
14 /// @headerfile Ice/Ice.h
15 class ICE_API Exception : public std::exception
16 {
17 public:
18 /// Default constructor.
19 Exception() noexcept = default;
20
21 /// Copy constructor. Initializes this exception with a copy of @p other.
22 /// @param other The exception to copy from.
23 Exception(const Exception& other) noexcept = default;
24
25 /// Copy assignment operator. Assigns the contents of @p rhs to this exception.
26 /// @param rhs The exception to copy from.
27 /// @return A reference to this exception.
28 Exception& operator=(const Exception& rhs) noexcept = default;
29
30 // Need out-of-line virtual function to avoid weak vtable, which in turn requires the default constructor,
31 // copy constructor, and copy assignment operator to be declared explicitly.
32 ~Exception() override;
33
34 /// Returns the type ID of this exception. This corresponds to the Slice type ID for Slice-defined exceptions,
35 /// and to a similar fully scoped name for other exceptions. For example
36 /// "::Ice::CommunicatorDestroyedException".
37 /// @return The type ID of this exception
38 [[nodiscard]] virtual const char* ice_id() const noexcept = 0;
39
40 /// Outputs a description of this exception to a stream.
41 /// @param os The output stream.
42 virtual void ice_print(std::ostream& os) const = 0;
43 };
44
45 /// Outputs a description of an Ice exception to a stream by calling Exception::ice_print on this exception.
46 /// @param os The output stream.
47 /// @param exception The exception to describe.
48 /// @return The output stream.
49 inline std::ostream& operator<<(std::ostream& os, const Exception& exception)
50 {
51 exception.ice_print(os);
52 return os;
53 }
54}
55
56#endif
Exception() noexcept=default
Default constructor.
virtual const char * ice_id() const noexcept=0
Returns the type ID of this exception.
virtual void ice_print(std::ostream &os) const =0
Outputs a description of this exception to a stream.
Abstract base class for all Ice exceptions.
Definition Exception.h:16
The Ice RPC framework.
Definition SampleEvent.h:59