KCrash

exception.cpp
1// SPDX-License-Identifier: LGPL-2.0-or-later
2
3#include "exception_p.h"
4
5#include <exception>
6
7#include <QUnhandledException>
8
9namespace
10{
11std::optional<KCrash::ExceptionMetadata> qUnhandledExceptionMetadata(const QUnhandledException &exception)
12{
13 auto exceptionPtr = exception.exception();
14 if (!exceptionPtr) {
15 return {};
16 }
17
18 try {
19 std::rethrow_exception(exceptionPtr);
20 } catch (const std::exception &e) {
21 return KCrash::ExceptionMetadata{
22 .ptr = exceptionPtr,
23 .klass = typeid(e).name(),
24 .what = e.what(),
25 };
26 }
27
28 return {};
29}
30} // namespace
31
32namespace KCrash
33{
34std::optional<ExceptionMetadata> exceptionMetadata()
35{
36 auto exceptionPtr = std::current_exception();
37 if (!exceptionPtr) {
38 return {};
39 }
40
41 try {
42 std::rethrow_exception(exceptionPtr);
43 } catch (const QUnhandledException &e) {
44 return qUnhandledExceptionMetadata(e);
45 } catch (const std::bad_alloc &e) {
46 return {};
47 } catch (const std::exception &e) {
48 return KCrash::ExceptionMetadata{
49 .ptr = exceptionPtr,
50 .klass = typeid(e).name(),
51 .what = e.what(),
52 };
53 }
54
55 return {};
56}
57} // namespace KCrash
This namespace contains functions to handle crashes.
QString name(StandardAction id)
std::exception_ptr exception() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:05:40 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.