Symbian3/SDK/Source/GUID-E65D91AE-482F-5592-B83C-0F29126C2EFA.dita
author Dominic Pinkman <dominic.pinkman@nokia.com>
Tue, 20 Jul 2010 12:00:49 +0100
changeset 13 48780e181b38
parent 7 51a74ef9ed63
permissions -rw-r--r--
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.

<?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-E65D91AE-482F-5592-B83C-0F29126C2EFA" xml:lang="en"><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 the 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>