Debugging leaves
Article Metadata
Original (Russian): Отладка сброса (leave)
Debugging Leave situations might be tedious. It would be much easier if the debugger could catch leaves and break the code execution. Luckily, there is a way to achieve it:
#define __LEAVE_IF_ERR(_c) TInt32 __reason = _c; \
if (__reason < 0) { \
__BREAKPOINT(); \
User::Leave(__reason); \
}The usage of this macro is similar to using User::LeaveIfError(), e.g. __LEAVE_IF_ERR(iFs.Connect()).


I think the following way looks more simple and also is a bit more correct:
#define __LEAVE_IF_ERR(_c) ((_c >= 0) || (({__BREAKPOINT(); User::Leave(_c);}), 0))The __BREAKPOINT macro is defined in e32def.h.
ivey
Purely out of curiosity: what do these assembly statements do? On Windows and on the target platform. Thanks!
tote_b5
to Tote: int 3 - is the breakpoint.
to Ivey: In you proposal statement _c is executed two times if leave occurs. If you wrap Int32 SomeFunction() to macro then the function would be called twice.
alones 14:01, 21 August 2007 (UTC)