Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 335877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:11:24+00:00 2026-05-12T10:11:24+00:00

For example, I’m writing a multi-threaded time-critical application that processes and streams audio in

  • 0

For example, I’m writing a multi-threaded time-critical application that processes and streams audio in real-time. Interruptions in the audio are totally unacceptable. Does this mean I cannot use the STL because of the potential slow down when an exception is thrown?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:11:24+00:00Added an answer on May 12, 2026 at 10:11 am

    It’s not clearly written in the previous answers, so:

    Exceptions happen in C++

    Using the STL or not won’t remove the RAII code that will free the objects’s resources you allocated.

    For example:

    void doSomething()
    {
        MyString str ;
        doSomethingElse() ;
    }
    

    In the code above, the compiler will generate the code to free the MyString resources (i.e. will call the MyString destructor), no matter what happens in the meantime including if if an exception is thrown by doSomethingElse or if you do a "return" before the end of the function scope.

    If you have a problem with that, then either you should revise your mindset, or try C.

    Exceptions are supposed to be exceptional

    Usually, when an exception occurs (and only when), you’ll have a performance hit.

    But then, the exception should only sent when:

    • You have an exceptional event to handle (i.e. some kind of error)
    • In very exceptional cases (i.e. a "massive return" from multiple function call in the stack, like when doing a complicated search, or unwinding the stack prior a thread graceful interruption)

    The keyword here is "exceptional", which is good because we are discussing "exception" (see the pattern?).

    In your case, if you have an exception thrown, chances are good something so bad happened your program would have crashed anyway without exception.

    In this case, your problem is not dealing with the performance hit. It is to deal with a graceful handling of the error, or, at worse, graceful termination of your program (including a "Sorry" messagebox, saving unsaved data into a temporary file for later recovery, etc.).

    This means (unless in very exceptional cases), don’t use exceptions as "return data". Throw exceptions when something very bad happens. Catch an exception only if you know what to do with that. Avoid try/catching (unless you know how to handle the exception).

    What about the STL ?

    Now that we know that:

    • You still want to use C++
    • Your aim is not to throw thousand exceptions each and every seconds just for the fun of it

    We should discuss STL:

    STL will (if possible) usually verify if you’re doing something wrong with it. And if you do, it will throw an exception. Still, in C++, you usually won’t pay for something you won’t use.

    An example of that is the access to a vector data.

    If you know you won’t go out of bounds, then you should use the operator [].

    If you know you won’t verify the bounds, then you should use the method at().

    Example A:

    typedef std::vector<std::string> Vector ;
    
    void outputAllData(const Vector & aString)
    {
       for(Vector::size_type i = 0, iMax = aString.size() ; i != iMax ; ++i)
        {
           std::cout << i << " : " << aString[i] << std::endl ;
        }
    }
    

    Example B:

    typedef std::vector<std::string> Vector ;
    
    void outputSomeData(const Vector & aString, Vector::size_type iIndex)
    {
       std::cout << iIndex << " : " << aString.at(iIndex) << std::endl ;
    }
    

    The example A "trust" the programmer, and no time will be lost in verification (and thus, less chance of an exception thrown at that time if there is an error anyway… Which usually means the error/exception/crash will usually happen after, which won’t help debugging and will let more data be corrupted).

    The example B asks the vector to verify the index is correct, and throw an exception if not.

    The choice is yours.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 165k
  • Answers 165k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There are a couple of variants of a rename command,… May 12, 2026 at 12:33 pm
  • Editorial Team
    Editorial Team added an answer There is currently no way to build CLS-compliant assemblies from… May 12, 2026 at 12:33 pm
  • Editorial Team
    Editorial Team added an answer You might want to look at Google Protocol Buffers or… May 12, 2026 at 12:33 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
For example, I issued an ALTER TABLE statement to create an index on a
For example, I have an ASP.NET form that is called by another aspx: string
For example, I want to populate a gridview control in an ASP.NET web page
For example, I rarely need: using System.Text; but it's always there by default. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.