Try-catch works with structured exception

This is a discussion on Try-catch works with structured exception within the C++ Programming forums, part of the General Programming Boards category; Thanks CornedBee, I feel your points are vague about whether to use try/catch or __try/__except for structured exception handling in ...

  1. #16
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks CornedBee,


    I feel your points are vague about whether to use try/catch or __try/__except for structured exception handling in C++ application.

    Do they have real functional differences or just programming style preference? :-)

    Quote Originally Posted by CornedBee View Post
    try/catch is part of the C++ standard. There's no such thing as a structured exception.
    In Visual C++, if you compile with /Eha, catch(...) will catch structured exceptions.


    __try/__except.


    I believe that SEH should not be used in C++ at all, except for some very, very specific use cases.

    The page I linked to contains more information on the requirements of using both SEH and C++ EH in the same program.

    regards,
    George

  2. #17
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    I have explained the functional differences in this thread or one of the many others you have created on the topic. If you can't remember, then go back and re-read.

    I think I've also been quite explicit on which you should use. Which part of "I believe that SEH should not be used in C++ at all, except for some very, very specific use cases." is vague?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #18
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Sorry CornedBee,


    1.

    Quote Originally Posted by CornedBee View Post
    I have explained the functional differences in this thread or one of the many others you have created on the topic. If you can't remember, then go back and re-read.
    I can not find. Could you quote please?

    2.

    Quote Originally Posted by CornedBee View Post
    I think I've also been quite explicit on which you should use. Which part of "I believe that SEH should not be used in C++ at all, except for some very, very specific use cases." is vague?
    I can understand. I just need to read and maintain some code containing structured exception.


    regards,
    George

  4. #19
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I guess you can't find it because in the last few weeks you have started at least four threads about exception handling - but if you go to your profile [click on your name in one of the recent posts], you can "find all threads started by george2", you can see all those threads.

    Or you can find all the posts by CornedBee - but there may be more of those.

    Failing that, perhaps the Search option, where you can select all sorts of things to search for, will help you.

    Also, when it comes to maintaining "old" code, you only make changes when and if there is a need to - so you shouldn't have to worry about changing between try/catch or __try/__except in most cases.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #20
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Mats,


    So your point is never using __try/__except and let me replace to try/catch, right?

    No risk? :-)

    Quote Originally Posted by matsp View Post
    I guess you can't find it because in the last few weeks you have started at least four threads about exception handling - but if you go to your profile [click on your name in one of the recent posts], you can "find all threads started by george2", you can see all those threads.

    Or you can find all the posts by CornedBee - but there may be more of those.

    Failing that, perhaps the Search option, where you can select all sorts of things to search for, will help you.

    Also, when it comes to maintaining "old" code, you only make changes when and if there is a need to - so you shouldn't have to worry about changing between try/catch or __try/__except in most cases.

    --
    Mats

    regards,
    George

  6. #21
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Since you're maintaining an existing application, our point is to minimize change. Is the error something you're supposed to correct, or did it appear after you changed something? If it's the latter, try to do the original change differently.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #22
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Right, when changing an existing application, the first question you need to answer is "Why am I changing this?" - if the answer is "It fixes the reported problem", then go ahead and change it. If the answer isn't that, then you PROBABLY shouldn't be changing it.

    The rule when changing existing code is "change it as little as possible".

    Of course, if the subject of your change is "C++ exceptions aren't always caught", then perhaps changing __try/__except to try/catch is the right thing to do.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #23
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks CornedBee and Mats,


    I decide to make a change. :-)

    Looks like /EHa mode with an additonal handler for set_se_translator to convert structured exception into C++ exception is the optimum solution -- since structured exception could also trigger destructor invocaton of local object during stack unwinding and if we translate structured exception into C++ exception, we can get more information from the exception.

    How do you think of this "final and optimum" solution?

    Quote Originally Posted by matsp View Post
    Right, when changing an existing application, the first question you need to answer is "Why am I changing this?" - if the answer is "It fixes the reported problem", then go ahead and change it. If the answer isn't that, then you PROBABLY shouldn't be changing it.

    The rule when changing existing code is "change it as little as possible".

    Of course, if the subject of your change is "C++ exceptions aren't always caught", then perhaps changing __try/__except to try/catch is the right thing to do.

    --
    Mats

    regards,
    George

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. exception and global variable
    By George2 in forum C++ Programming
    Replies: 12
    Last Post: 01-28-2008, 06:12 PM
  2. Replies: 5
    Last Post: 06-06-2007, 11:10 PM
  3. Problem with the exception class in MINGW
    By indigo0086 in forum C++ Programming
    Replies: 6
    Last Post: 01-20-2007, 12:12 PM
  4. try
    By Unregistered in forum C++ Programming
    Replies: 13
    Last Post: 08-20-2002, 08:46 AM
  5. Developing Custom Exception Handler :: C++
    By kuphryn in forum C++ Programming
    Replies: 4
    Last Post: 02-20-2002, 03:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21