Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
src_corelib_tools_qscopeguard.cpp
Go to the documentation of this file.
1
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Sérgio Martins <sergio.martins@kdab.com>
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4
#
include
<
QScopeGuard
>
5
6
int
code_that_might_throw_exceptions
() {
return
0; };
7
8
//! [0]
9
void
myComplexCodeWithMultipleReturnPoints
(
int
v)
10
{
11
// The lambda will be executed right before your function returns
12
auto
cleanup = qScopeGuard([] {
/* code you want executed goes HERE; */
});
13
14
if
(v == -1)
15
return
;
16
17
int
v2 =
code_that_might_throw_exceptions
(
)
;
18
19
if
(v2 == -1)
20
return
;
21
22
//...
23
}
24
//! [0]
code_that_might_throw_exceptions
int code_that_might_throw_exceptions()
Definition
src_corelib_tools_qscopeguard.cpp:6
myComplexCodeWithMultipleReturnPoints
void myComplexCodeWithMultipleReturnPoints(int v)
[0]
Definition
src_corelib_tools_qscopeguard.cpp:9
qtbase
src
corelib
doc
snippets
code
src_corelib_tools_qscopeguard.cpp
Generated on
for Qt by
1.14.0