Which one should I use?
catch (_com_error e)  
or
catch (_com_error& e)
                The second. Here is my attempt at quoting Sutter
"Throw by value, catch by reference"
Learn to
catchproperly: Throw exceptions by value (not pointer) and catch them by reference (usually toconst). This is the combination that meshes best with exception semantics. When rethrowing the same exception, prefer justthrow;tothrow e;.
Here's the full Item 73. Throw by value, catch by reference.
The reason to avoid catching exceptions by value is that it implicitly makes a copy of the exception. If the exception is of a subclass, then information about it will be lost.
try { throw MyException ("error") } 
catch (Exception e) {
    /* Implies: Exception e (MyException ("error")) */
    /* e is an instance of Exception, but not MyException */
}
Catching by reference avoids this issue by not copying the exception.
try { throw MyException ("error") } 
catch (Exception& e) {
    /* Implies: Exception &e = MyException ("error"); */
    /* e is an instance of MyException */
}
                        Personally, I would go for the third option:
catch (const _com_error& e)
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With