An introduction to the Symbian exception handling mechanism and how memory cleanup is managed.
Two of the most fundamental idioms within Symbian C++ are its lightweight exception handling, which is called leaving, and its use of a cleanup stack to manage the destruction of objects and cleanup of resources in the event of an exceptional condition (such as allocation failure due to insufficient memory).
A leaving function may be described as one that, when it detects an error, exits at the point of the error and unwinds, performing memory cleanup, until a leave handler is found. This is in contrast to a function that returns an error back to the calling function.
Symbian C++ was designed before the C++ standard had been formalized,
and before exception handling using try
, catch
and throw
was fully supported by
compilers. In addition, exception-handling support had the potential
to bloat the size of compiled code and add to memory overheads at
runtime, so standard C++ exception handling was not used.
The Symbian platform now supports C++ standard exceptions, which makes it easier to port existing C++ code. However, leaves are still a fundamental part of Symbian error handling and are used throughout the system.
Copyright note. The material in this topic is based with permission on a Symbian Foundation wiki article Leaves & The Cleanup Stack which is part of the series The Fundamentals of Symbian C++. The version used was that available at http://developer.symbian.org/ on 3 November 2010. The content in this page is licensed under the Creative Commons Attribution-Share Alike 2.0 UK: England & Wales License (http://creativecommons.org/licenses/by-sa/2.0/uk).