CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2003
    Location
    Illinois
    Posts
    9

    Is exception handling time-consuming?

    I have a hashtable and I may add repeated elements to it. It is pretty time-consuming to get hash code. So I don't want to write like following:

    if(!ht.Contains(x))
    ht.Add(x);

    I want to write like this:

    try{
    ht.Add(x);
    }
    catch(ArgumentException e){
    }

    I am wondering that how fast exception handling is? Will it generate an interrupt?

    Thanks

  2. #2
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    no actually using try .. catch blocks is actually a good idea
    I mean you should know prior to use it. will that statement cause some exception. if that the case the put it in try ..catch blocks. the execution won't get slow
    untill
    each statement throws exception.


    one more thing to remember that
    statement like simple ones which never throws exception should not be the candidates for exceptions.

    -Paresh
    - Software Architect

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