KDE

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Exception handling

    5 answers - 1983 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hi,
    I admit I never really used exceptions and I don't know more about
    them, but the syntax. ;-) I have a problem here, it seems that the
    exceptions are not caught. The code is:
    try
    {
    parent.insertBefore(node, nextSibling);
    }
    catch(DM::DMException e)
    {
    kdDebug(25001)<< "kafkaCommon::insertDomNode() - ERRR code :"
    << e.code << endl;
    }
    This should display the debug message if some (DM::DMException
    exception was thrown in insertBefore. And indeed there is an exception
    thrown there:
    if (exceptioncode)
    throw DMException(exceptioncode);
    The problem is that the application crashes instead of catching the
    exception. console I get:
    "terminate called after throwing an instance of 'DM::DMException'"
    and the backtrace is:
    KCrash handler]
    #4 0xffffe410 in __kernel_vsyscall ()
    #5 0x41c37541 in raise () from /lib/tls/libc.so.6
    #6 0x41c38dbb in abort () from /lib/tls/libc.so.6
    #7 0x41bbf489 in ()
    from /usr/lib/libstdcso.6
    #8 0x41bbce15 in __gxx_personality_v0 () from /usr/lib/libstdcso.6
    #9 0x41bbce52 in std::terminate () from /usr/lib/libstdcso.6
    #10 0x41bbcfba in __cxa_throw () from /usr/lib/libstdcso.6
    #11 0x4066f11e in DM::Node::insertBefore ()
    from /opt/kde3/lib/libkhtml.so.4
    #12 0x082da6e7 in kafkaCommon::insertDomNode (node=@0xbfdec85c,
    parent=@0xbfdec854, nextSibling=@0xbfdec84c, rootNode=@0xbfdec844)
    at kafkacommon.cpp:3695
    The kafkacommon.cpp is in a separate convenience library, where the
    Makefile.am contains:
    KDE_CXXFLAGS= $(USE_EXCEPTINS)
    I even tried to enable the exceptions for the main executable as well
    (and I checked that -fexceptions is appended to the g++ options), but
    it still crashes
    Any idea how can I catch the exceptions? Should I enable them for every
    source file and convenience library that is used inside the
    application? ?
    Andras
  • No.1 | | 308 bytes | |

    Friday 19 May 2006 12:08, Andras Mantia wrote:
    Any idea how can I catch the exceptions? Should I enable them for
    every source file and convenience library that is used inside the
    application? ?

    Nevermind, I found it: ,
    "Problems with C++ exceptions (please read!) " section.

    Andras
  • No.2 | | 639 bytes | |

    Friday 19 May 2006 13:29, A W wrote:
    Hi Andras.

    Friday 19 May 2006 11:59, Andras Mantia wrote:
    Friday 19 May 2006 12:08, Andras Mantia wrote:
    Any idea how can I catch the exceptions? Should I enable them for
    every source file and convenience library that is used inside the
    application? ?

    Nevermind, I found it: ,
    "Problems with C++ exceptions (please read!) " section.

    if it was a visibility issue how did your app link? shouldn't you get
    unresolved symbols?

    No. Read the link I posted, it explains that you will not get linking
    errors, but only malfunctioning code.

    Andras
  • No.3 | | 756 bytes | |

    Friday 19 May 2006 11:08, Andras Mantia wrote:
    Hi,

    I admit I never really used exceptions and I don't know more about
    them, but the syntax. ;-) I have a problem here, it seems that the
    exceptions are not caught. The code is:
    try
    {
    parent.insertBefore(node, nextSibling);
    }
    catch(DM::DMException e)
    {
    kdDebug(25001)<< "kafkaCommon::insertDomNode() - ERRR code :"
    << e.code << endl;
    }

    a related note, *always* catch exceptions by (non-const) reference. I.e.

    catch(DM::DMException& e)

    , you'll slice the exception object, run into multiple exception and
    what have you.

    Hmm maybe I should see if someone suggested a warning about this to the gcc
    people.
  • No.4 | | 252 bytes | |

    Saturday 20 May 2006 14:39, Esben Mose Hansen wrote:
    a related note, *always* catch exceptions by (non-const)
    reference. I.e.
    catch(DM::DMException& e)
    The code was written in a similar way, I just played with it. ;-)
    Andras
  • No.5 | | 474 bytes | |

    Saturday 20 May 2006 15:01, A W wrote:

    a related note, *always* catch exceptions by (non-const)
    reference. I.e.

    catch(DM::DMException& e)

    Why non-const?

    I think this is mere convention. I can't of the top of my head see a reason
    where catching by const reference really hurts, except if you need access to
    non-const member funtions on the exception object. Throwing const ob jects
    would be a quite strange thing to do, though :)

Re: Exception handling


max 4000 letters.
Your nickname that display:
In order to stop the spam: 9 + 8 =
QUESTION ON "KDE"

EMSDN.COM