Symbian3/SDK/Source/GUID-E65D91AE-482F-5592-B83C-0F29126C2EFA.dita
author Dominic Pinkman <Dominic.Pinkman@Nokia.com>
Thu, 21 Jan 2010 18:18:20 +0000
changeset 0 89d6a7a84779
permissions -rw-r--r--
Initial contribution of Documentation_content according to Feature bug 1266 bug 1268 bug 1269 bug 1270 bug 1372 bug 1374 bug 1375 bug 1379 bug 1380 bug 1381 bug 1382 bug 1383 bug 1385

<?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 xml:lang="en" id="GUID-E65D91AE-482F-5592-B83C-0F29126C2EFA"><title>Using Signals to Handle Exceptions </title><prolog><metadata><keywords/></metadata></prolog><conbody><p>Signals provide an alternative method (to checking return values) of handling exceptions or failures. The following example code demonstrates how you can check the return value for a failure and also how you can register a handler for handling the failure asynchronously: </p> <codeblock id="GUID-49B4A39A-34F5-54D1-AD97-5AD50EFD9786" xml:space="preserve">#include &lt;signal.h&gt;
#include &lt;stdio.h&gt;
int func()
    {
    int success = 1;
    // function logic
    // success == 1  - Indicates that the function logic succeeded
    // success == 0  - Indicates that the function logic failed
    if(success)
        return 0;
    else
        {
        raise(SIGUSR1);
        return -1;
        }
    }
void sighandler(int signum)
    {
    if(signum == SIGUSR1)
        // 'signal' method for checking failure
        printf(“Error: An error occured in func().”);
    else
        printf(“Error: Unknown signal”);
    }
int main(void)
    {
    int retval = 0;
    // When SIGUSR1 arrives, invoke sighandler()
    signal(SIGUSR1,sighandler);
    retval = func();
    if(retval == -1)
        // The return value method used for checking failure
        printf("Error: An error occured in func().");  
    }</codeblock> </conbody><related-links><link href="GUID-66C1493D-5B85-558A-9A39-454E6EBA307B.dita"><linktext>Signal Emulation on Symbian
                Platform</linktext> </link> <link href="GUID-186B9876-2A08-5F23-BB49-49EC34C51507.dita"><linktext>Using Signals to Terminate Processes</linktext> </link> <link href="GUID-6CF8A41B-C2DD-5D57-A71D-6405CE08A06B.dita"><linktext>Using Signals to Handle Asynchronous
                Events</linktext> </link> </related-links></concept>