CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863

    Size of try/catch blocks

    If I have a very large function body which contains several
    calls to functions which throw similar exceptions is it less
    costly to have several try/catch blocks or one try/catch block
    for the entire function body. Lets assume that the catch blocks
    all perform the same function.
    Wakeup in the morning and kick the day in the teeth!! Or something like that.

    "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."

  2. #2
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    well if they perform the same function, then why not catch(...) unless you are looking at the exception....so I know soul this isn't what you are looking for, so explain a bit more....

  3. #3
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863
    what is mean is say F1, F2, ...., FN throw exceptions
    and I have

    PHP Code:
    void FOO()
    {

              
    F1();
    ...

              
    F2();
    ...
    ...
    ...
              
    FN();

    As I understand it (which is not very well) I am going to pay
    a price for having to keep track of code within try/catch for
    stack unwinding. Now is this price worse if I use

    PHP Code:
    void FOO()
    {
        try
        {
              
    F1();
    ...

              
    F2();
    ...
    ...
    ...
              
    FN();
         }
         catch
         {
         }

    }

    as 
    oppossed to 

    void FOO
    ()
    {
        try
        {
              
    F1();
        }
        catch
         {
         }
    ...

        try
        {
               
    F2();
        }
        catch
         {
         }
    ... 
    ...
    ...
        try
        {
               
    FN();
         }
         catch
         {
         }


    Now maybe this is a dumb question and the difference is insignificant.
    Wakeup in the morning and kick the day in the teeth!! Or something like that.

    "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."

  4. #4
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Ok...

    just one try and multiple catchs...it matters not what is thrown, that a catch is there...you could disassembly it and look, but I would gather that the optimizer for the compiler would be the same....and no I haven't looked dumpbin /disasm .exe/.dll if your interested...

  5. #5
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863
    Got it Mick, thanks...
    Wakeup in the morning and kick the day in the teeth!! Or something like that.

    "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."

  6. #6
    Join Date
    Dec 2002
    Posts
    1,050
    Bobby Schmidt's 17 part exception series in the MSDN talks about
    some overhead in section 4: even looks at the generated asm.
    Maybe some details for you ? Probably different in VC7.

    Handling Exceptions in C and C++, Part 4

  7. #7
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Originally posted by mdmd
    Bobby Schmidt's 17 part exception series in the MSDN talks about
    some overhead in section 4: even looks at the generated asm.
    Maybe some details for you ? Probably different in VC7.

    Handling Exceptions in C and C++, Part 4
    You should have stated at part 1....these go to 17,,,,

  8. #8
    Join Date
    Dec 2002
    Posts
    1,050
    Originally posted by Mick
    You should have stated at part 1....these go to 17,,,,
    I started from 17 and went backwards thinking he wouldn't be
    "spelunking a tiny way into assembly language" untill the
    end; I never made it to part 1.
    Its good enough to read through again fully. Next time I'll start
    from Handling Exceptions in C and C++, Part 1

  9. #9
    Join Date
    Sep 2002
    Location
    Maryland - Fear The Turtle!
    Posts
    7,537
    Originally posted by mdmd
    I started from 17 and went backwards thinking he wouldn't be
    "spelunking a tiny way into assembly language" untill the
    end; I never made it to part 1.
    Its good enough to read through again fully. Next time I'll start
    from Handling Exceptions in C and C++, Part 1
    I only glanced through...seemed like a good read, and after all it's 17 parts..what can be wrong with that??? unless yer a liberal then it's really wrong

  10. #10
    Join Date
    Nov 2002
    Location
    Los Angeles, California
    Posts
    3,863
    Thanks MDMD that is what I needed...information.
    Wakeup in the morning and kick the day in the teeth!! Or something like that.

    "i don't want to write leak free code or most efficient code, like others traditional (so called expert) coders do."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured