DocWire SDK
DocWire SDK: Deterministic, auditable, and secure data processing in C++20. On-premise by default. No compromises on computational speed.
Toggle main menu visibility
Loading...
Searching...
No Matches
contains_type.h
1
/*********************************************************************************************************************************************/
2
/* DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. */
3
/* Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, */
4
/* document analysis. Offline processing possible for security and confidentiality */
5
/* */
6
/* Copyright (c) SILVERCODERS Ltd, http://silvercoders.com */
7
/* Project homepage: https://github.com/docwire/docwire */
8
/* */
9
/* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-DocWire-Commercial */
10
/*********************************************************************************************************************************************/
11
12
#ifndef DOCWIRE_CONTAINS_TYPE_H
13
#define DOCWIRE_CONTAINS_TYPE_H
14
15
#include "error.h"
16
#include <exception>
17
18
namespace
docwire::errors
19
{
20
24
template
<
typename
T>
25
bool
contains_type
(
const
std::exception& e)
26
{
27
try
28
{
29
const
errors::base
& error =
dynamic_cast<
const
errors::base
&
>
(e);
30
for
(
size_t
i = 0; i < error.
context_count
(); ++i)
31
{
32
if
(error.
context_type_id
(i) ==
type_id_of<T>
())
33
return
true
;
34
}
35
}
36
catch
(
const
std::bad_cast&)
37
{
38
// e is not errors::base, but may still have nested exceptions
39
}
40
41
try
42
{
43
std::rethrow_if_nested(e);
44
}
45
catch
(
const
std::exception& nested_ex)
46
{
47
return
contains_type<T>
(nested_ex);
48
}
49
catch
(...) {}
50
51
return
false
;
52
}
53
54
}
// namespace docwire::errors
55
56
#endif
// DOCWIRE_CONTAINS_TYPE_H
docwire::errors
Provides features for reporting and handling errors with context data using nested exceptions.
Definition
contains_type.h:19
docwire::errors::contains_type
bool contains_type(const std::exception &e)
Checks if the given nested exceptions chain contains a specific type of context.
Definition
contains_type.h:25
docwire::type_id_of
consteval type_id type_id_of() noexcept
Returns a compile-time strong identifier for type T.
Definition
type_id.h:68
docwire::errors::base
Base class for all exceptions in the SDK.
Definition
error.h:76
docwire::errors::base::context_type_id
virtual type_id context_type_id(size_t index) const noexcept=0
Get the type information of the context.
docwire::errors::base::context_count
virtual size_t context_count() const noexcept=0
Get the number of context items.
contains_type.h
Generated by
1.18.0