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

  • SEARCH
  • Home
  • 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 9246411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:28:52+00:00 2026-06-18T09:28:52+00:00

When catching an exception by reference is the only advantage that i get is

  • 0

When catching an exception by reference is the only advantage that i get is avoiding a copy of the exception object being made? Basically the difference between

try
{
    CString a_csSQL = _T("SELECT * FROM Library");
    CDatabase aDB;
    aDB.OpenEx(g_csConnectionStringWdDSN,CDatabase::noOdbcDialog));
    aDB.ExecuteSQL(a_csSQL);
}
catch(CDBException *& ex)
{
    ex->Delete();
}

AND

try
{
    CString a_csSQL = _T("SELECT * FROM Library");
    CDatabase aDB;
    aDB.OpenEx(g_csConnectionStringWdDSN,CDatabase::noOdbcDialog))
    aDB.ExecuteSQL(a_csSQL);
}
catch(CDBException * ex)
{
    ex->Delete();
}
  • 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-06-18T09:28:53+00:00Added an answer on June 18, 2026 at 9:28 am

    The difference between the two codes you posted is that the first one catches a pointer to an exception by reference, and the second one catches a pointer to an exception by value. In neither case is an exception copied, since you’re dealing with pointers.

    In general, exceptions should be thrown by value, and caught by reference. The C++ standard library is designed with this expectation in mind. However, older libraries, (MFC for instance) throw exceptions by pointer as you do here, and are expected to be caught by pointer.

    There’s no effective difference between catching a pointer by value and by reference, except that if you catch by reference that gives you the (completely useless) option of deleting the exception, allocating a new exception with that same pointer, and rethrowing the same exception-pointer.

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

Sidebar

Related Questions

Is catching an exception thrown in a loaded shared library portable? I've noticed that
I can see on catching an exception that I can print e.getCause() , though
I am trying to read file in Haskell with exception catching but cant get
I am using the exception catching procedure which is the module to track the
I have a problem in catching an exception. I am trying to rethrow an
I'm catching all exceptions within: java.lang.Throwable /page.xhtml java.lang.Error /page.xhtml But what If I get
I had someone mention to me that catching all exceptions is not necessarily good
Possible Duplicate: How does one tell if an IDisposable object reference is disposed? Is
If I use Microsoft.ApplicationServer.Caching.Client and Microsoft.ApplicationServer.Caching.Core assembly I get exception: The type or namespace
When catching an exception in .NET, you can have as many type-specific exception blocks

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.