Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



Location: e32std.h
Link against:

TRAP

TRAP(_r,_s) {TTrap __t;if (__t.Trap(_r)==0){_s;TTrap::UnTrap();}}

Support

Supported from 5.0

Description

Executes the set of C++ statements _s under a trap harness — use this macro as a C++ statement.

_r must be a TInt which has already been declared; if any of the C++ statements _s leaves, then the leave code is returned in _r, otherwise _r is set to KErrNone.

_s can consist of multiple C++ statements; in theory, _s can consist of any legal C++ code but in practice, such statements consist of simple function calls, e.g. Foo() or an assignment of some value to the result of a function call, e.g. functionValue=GetFoo().

A cleanup stack is constructed for the set of C++ statements _s. If any function in _s leaves, objects pushed to the cleanup stack are cleaned-up. In addition, if any of the C++ statements in _s leaves, then remaining C++ code in _s is not executed and any variables which are assigned within that remaining code are not defined.

Note:

Parameters

_r

an lvalue, convertible to TInt&, which will receive the result of any User::Leave() executed within _s or, if no leave occurred, it will be set to KErrNoneThe value of _r on entry is not used.

_s

C++ statements which will be executed under a trap harness.

See also: