18# include "fleece/slice.hh"
146 if ( outError ) *outError = make(
domain,
code, message);
152 static
void fromException(const std::exception& e,
C4Error*
C4NULLABLE outError) noexcept {
153 if ( outError ) *outError = fromException(e);
157 if ( outError ) *outError = fromCurrentException();
160 static void warnCurrentException(
const char* inFunction)
noexcept;
165 [[noreturn]] static
void raise(
C4Error e) { e.raise(); }
167 static void setCaptureBacktraces(
bool)
noexcept;
168 static bool getCaptureBacktraces() noexcept;
170 [[noreturn]]
void raise() const;
172 bool operator==(const
C4Error& b)
const {
return code == b.code && (
code == 0 ||
domain == b.domain); }
174 bool operator!=(
const C4Error& b)
const {
return !(*
this == b); }
176 explicit operator bool()
const {
return code != 0; }
178 bool operator!()
const {
return code == 0; }
180 [[nodiscard]] std::string message()
const;
181 [[nodiscard]] std::string description()
const;
182 [[nodiscard]] std::string backtrace()
const;
184 [[nodiscard]]
bool mayBeTransient() const noexcept;
185 [[nodiscard]]
bool mayBeNetworkDependent() const noexcept;
192# define kC4NoError ((C4Error){})
#define NODISCARD
Definition CompilerSupport.h:59
#define CBL_CORE_API
Definition c4Compat.h:134
#define C4NULLABLE
Definition c4Compat.h:38
#define C4_ENUM(_type, _name)
Definition c4Compat.h:62
#define C4API
Definition c4Compat.h:114
#define C4_ASSUME_NONNULL_BEGIN
Definition c4Compat.h:36
#define C4API_END_DECLS
Definition c4Compat.h:116
#define __printflike(fmtarg, firstvararg)
Definition c4Compat.h:143
#define C4API_BEGIN_DECLS
Definition c4Compat.h:115
#define C4_ASSUME_NONNULL_END
Definition c4Compat.h:37
CBL_CORE_API FLStringResult c4error_getBacktrace(C4Error error)
Returns the stack backtrace, if any, associated with a C4Error.
CBL_CORE_API FLSliceResult c4error_getDescription(C4Error error)
Returns a description of an error, including the domain and code as well as the message.
CBL_CORE_API void c4error_setCaptureBacktraces(bool)
If set to true, then when a C4Error is created the current thread's stack backtrace will be captured ...
#define kC4NoError
Definition c4Error.h:192
CBL_CORE_API char * c4error_getDescriptionC(C4Error error, char *outBuffer, size_t bufferSize)
Returns a description of an error, including the domain and code as well as the message.
C4NetworkErrorCode
Definition c4Error.h:97
NODISCARD CBL_CORE_API C4Error c4error_make(C4ErrorDomain domain, int code, FLString message)
Creates a C4Error struct with the given domain and code, and associates the message with it.
CBL_CORE_API bool c4error_mayBeNetworkDependent(C4Error err)
Returns true if this error might go away when the network environment changes, i.e.
CBL_CORE_API bool c4error_getCaptureBacktraces(void)
C4ErrorDomain
Definition c4Error.h:37
C4ErrorCode
Definition c4Error.h:52
NODISCARD CBL_CORE_API C4Error NODISCARD CBL_CORE_API C4Error CBL_CORE_API void c4error_return(C4ErrorDomain domain, int code, FLString message, C4Error *outError)
Creates and stores a C4Error in *outError, if not NULL.
NODISCARD CBL_CORE_API C4Error NODISCARD CBL_CORE_API C4Error c4error_vprintf(C4ErrorDomain domain, int code, const char *format, va_list args) __printflike(3
Same as c4error_printf, but with a premade va_list.
CBL_CORE_API FLStringResult c4error_getMessage(C4Error error)
Returns an error message describing a C4Error.
NODISCARD CBL_CORE_API C4Error c4error_printf(C4ErrorDomain domain, int code, const char *format,...) __printflike(3
Creates a C4Error struct with the given domain and code, formats the message as with printf,...
CBL_CORE_API bool c4error_mayBeTransient(C4Error err)
Returns true if this is a network error that may be transient, i.e.
@ kC4NetErrTLSCertExpired
Definition c4Error.h:104
@ kC4NetErrTLSCertUnknownRoot
Definition c4Error.h:108
@ kC4NetErrAddressNotAvailable
Definition c4Error.h:122
@ kC4NetErrUnknown
Definition c4Error.h:110
@ kC4NetErrConnectionAborted
Definition c4Error.h:114
@ kC4NetErrNetworkUnreachable
Definition c4Error.h:118
@ kC4NetErrHostDown
Definition c4Error.h:120
@ kC4NetErrTooManyRedirects
Definition c4Error.h:102
@ kC4NetErrConnectionRefused
Definition c4Error.h:116
@ kC4NetErrTimeout
Definition c4Error.h:100
@ kC4NetErrDNSFailure
Definition c4Error.h:98
@ kC4NetErrNotConnected
Definition c4Error.h:119
@ kC4NetErrTLSCertRejectedByPeer
Definition c4Error.h:107
@ kC4NetErrTLSCertNameMismatch
Definition c4Error.h:112
@ kC4NetErrNetworkReset
Definition c4Error.h:113
@ kC4NetErrInvalidRedirect
Definition c4Error.h:109
@ kC4NetErrHostUnreachable
Definition c4Error.h:121
@ kC4NetErrConnectionReset
Definition c4Error.h:115
@ kC4NetErrTLSCertUntrusted
Definition c4Error.h:105
@ kC4NetErrBrokenPipe
Definition c4Error.h:123
@ kC4NetErrNetworkDown
Definition c4Error.h:117
@ kC4NetErrTLSCertRequiredByPeer
Definition c4Error.h:106
@ kC4NetErrUnknownHost
Definition c4Error.h:99
@ kC4NumNetErrorCodesPlus1
Definition c4Error.h:125
@ kC4NetErrTLSCertRevoked
Definition c4Error.h:111
@ kC4NetErrTLSHandshakeFailed
Definition c4Error.h:103
@ kC4NetErrUnknownInterface
Definition c4Error.h:124
@ kC4NetErrInvalidURL
Definition c4Error.h:101
@ WebSocketDomain
Definition c4Error.h:43
@ POSIXDomain
Definition c4Error.h:39
@ MbedTLSDomain
Definition c4Error.h:44
@ NetworkDomain
Definition c4Error.h:42
@ kC4MaxErrorDomainPlus1
Definition c4Error.h:46
@ FleeceDomain
Definition c4Error.h:41
@ LiteCoreDomain
Definition c4Error.h:38
@ SQLiteDomain
Definition c4Error.h:40
@ kC4ErrorCrypto
Definition c4Error.h:76
@ kC4ErrorInvalidQuery
Definition c4Error.h:77
@ kC4ErrorNotADatabaseFile
Definition c4Error.h:73
@ kC4ErrorBadRevisionID
Definition c4Error.h:56
@ kC4ErrorIOError
Definition c4Error.h:65
@ kC4ErrorUnsupported
Definition c4Error.h:72
@ kC4ErrorNotOpen
Definition c4Error.h:58
@ kC4ErrorUnimplemented
Definition c4Error.h:54
@ kC4ErrorBadDocID
Definition c4Error.h:83
@ kC4ErrorNotFound
Definition c4Error.h:59
@ kC4ErrorInvalidParameter
Definition c4Error.h:61
@ kC4ErrorMissingIndex
Definition c4Error.h:78
@ kC4NumErrorCodesPlus1
Definition c4Error.h:88
@ kC4ErrorBusy
Definition c4Error.h:69
@ kC4ErrorUnsupportedEncryption
Definition c4Error.h:55
@ kC4ErrorNotWriteable
Definition c4Error.h:67
@ kC4ErrorMemoryError
Definition c4Error.h:66
@ kC4ErrorWrongFormat
Definition c4Error.h:75
@ kC4ErrorNotInTransaction
Definition c4Error.h:70
@ kC4ErrorUnexpectedError
Definition c4Error.h:62
@ kC4ErrorRemoteError
Definition c4Error.h:80
@ kC4ErrorDatabaseTooNew
Definition c4Error.h:82
@ kC4ErrorDeltaBaseUnknown
Definition c4Error.h:86
@ kC4ErrorTransactionNotClosed
Definition c4Error.h:71
@ kC4ErrorCantOpenFile
Definition c4Error.h:64
@ kC4ErrorInvalidQueryParam
Definition c4Error.h:79
@ kC4ErrorConflict
Definition c4Error.h:60
@ kC4ErrorDatabaseTooOld
Definition c4Error.h:81
@ kC4ErrorCorruptDelta
Definition c4Error.h:87
@ kC4ErrorCorruptData
Definition c4Error.h:68
@ kC4ErrorCorruptRevisionData
Definition c4Error.h:57
@ kC4ErrorCantUpgradeDatabase
Definition c4Error.h:84
@ kC4ErrorAssertionFailed
Definition c4Error.h:53
An error value.
Definition c4Error.h:133
C4ErrorDomain domain
Definition c4Error.h:134
unsigned internal_info
Definition c4Error.h:136
int code
Definition c4Error.h:135
A simple reference to a block of memory.
Definition FLSlice.h:45
A heap-allocated block of memory returned from an API call.
Definition FLSlice.h:63