Symbian3/PDK/Source/GUID-7E967B81-2DBF-5A89-B74B-93FEA5515685.dita
author Dominic Pinkman <Dominic.Pinkman@Nokia.com>
Thu, 11 Mar 2010 18:02:22 +0000
changeset 3 46218c8b8afa
parent 1 25a17d01db0c
child 5 f345bda72bc4
permissions -rw-r--r--
week 10 bug fix submission (SF PDK version): Bug 1892, Bug 1897, Bug 1319. Also 3 or 4 documents were found to contain code blocks with SFL, which has been fixed. Partial fix for broken links, links to Forum Nokia, and the 'Symbian platform' terminology issues.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="GUID-7E967B81-2DBF-5A89-B74B-93FEA5515685" xml:lang="en"><title>How
to use new with automatic leave on failure</title><shortdesc>Provides code snippets to show you how to use <codeph>new</codeph> with
automatic leave on failure</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
<p>The case of <codeph>new</codeph> failing is so common that a version of <codeph>operator
new()</codeph> has been written which takes a single parameter <codeph>ELeave</codeph>,
indicating that it must leave if it was unable to allocate memory.</p>
<p>Use <codeph>operator new()</codeph> so that there is no need to check the
result of the <codeph>new</codeph>.</p>
<codeblock id="GUID-E898C802-28E7-5330-B4F1-08829BECB4AE" xml:space="preserve">void doExampleL()
 {
 // attempt to allocate, leave if could not
 CExample* myExample = new (ELeave) CExample;
 // new (ELeave) replaces new followed by check
 // do something
 myExample-&gt;iInt = 5;
 testConsole.Printf(_LIT("Value of iInt is %d.\n"),myExample-&gt;iInt);
 // delete
 delete myExample;
 }</codeblock>
</conbody></concept>