9 messages in com.mysql.lists.plusplusRe: Catching Exceptions| From | Sent On | Attachments |
|---|---|---|
| Adam Clauss | 26 May 2003 16:31 | |
| Ben Clewett | 27 May 2003 00:42 | |
| Markus Gerwinski | 27 May 2003 00:59 | |
| Murr...@Comneon.com | 27 May 2003 01:16 | |
| Markus Gerwinski | 27 May 2003 01:38 | |
| Murr...@Comneon.com | 27 May 2003 01:46 | |
| Adam Clauss | 27 May 2003 11:17 | |
| Sinisa Milivojevic | 28 May 2003 03:52 | |
| Warren Young | 28 May 2003 09:05 |
| Subject: | Re: Catching Exceptions![]() |
|---|---|
| From: | Warren Young (war...@etr-usa.com) |
| Date: | 05/28/2003 09:05:13 AM |
| List: | com.mysql.lists.plusplus |
Adam Clauss wrote:
I noticed that the exceptions were being caught by pointer. I recommend that you catch them by const reference, as you always should. It might make a difference with the MSVC++ compiler.
Exactly right. Any compiler that lets you catch an exception through a pointer like this is confusing pointer semantics with reference semantics. Sure, they may be implemented the same way under the hood, but at the C++ level, they're distinct.
Although... Why const reference? I've typically just done it by value.
Because if you catch an exception by value, a copy has to be made of the exception object. That's inefficient with most exception objects, and also usually unnecessary. Sometimes, a copy might even be impossible, such as in the case of a bad_alloc exception.
If you just need to call a why() method on the exception object or something simple like that, a const reference avoids the copy, and ensures that your code doesn't modify the original exception object.




