Week 32 contribution of PDK documentation content. See release notes for details. Fixes bug Bug 3582
<?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-8DF1C625-7963-55E9-BEEC-C9E37936F8CF" xml:lang="en"><title>Howto use User::Leave()</title><shortdesc>Provides a code snippet to explain how to use <codeph>User::Leave()</codeph>.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody><p>You can use the <codeph>User::Leave()</codeph> function to terminate afunction’s processing immediately when an exception condition occurs. In theexample below, if the <codeph>new</codeph> fails, the function calls <codeph>User::Leave()</codeph> withan error code. The return type of the function is <codeph>void</codeph>, becauseit is not necessary to use it to return error information.</p><codeblock id="GUID-98542124-DB23-5A8F-8387-F0781B32D1F2" xml:space="preserve">void doExampleL() { CExample* myExample = new CExample; if (!myExample) User::Leave(KErrNoMemory); // leave used in place of return to indicate an error // do something myExample->iInt = 5; testConsole.Printf(_LIT("Value of iInt is %d.\n"),myExample->iInt); // delete delete myExample; }</codeblock><section id="GUID-98FF9DEC-DC09-43DE-ABAD-3EE9C2597A85"><title>Notes</title> <ul><li id="GUID-7891ACB0-D39E-5982-BF3E-43DD01281F77"><p>the <codeph>L</codeph> suffixon a function name indicates that it may leave</p> </li></ul> </section></conbody></concept>