Click here to Skip to main content
15,943,799 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
In exception handling we can catch exception in three way.i.e by value,by reference,by pointer.may i know the three difference when they are use and why?
Sandeep Mewara 21-Jan-11 3:19am    

See Scott Meyers' More Effective C++ Item 13, Catch exceptions by reference, 68

In general, using pointers results when unnecessary in the worst performance.
Using by value is slower than by reference unless you are dealing with a fundamental type like an int.
Share this answer
satyabrat subudhi 21-Jan-11 1:41am    
can you suggest me any link for exception handeling?
T2102 21-Jan-11 1:42am    
google for that book and see page 68
Obligatory link to the C++ FAQ on Exceptions:[^]
Share this answer
when throwing an exception using a dynamic object E.g.

throw new MyErrObj( MyErrCode );

that only needs to stay in memory until a catch handler decides it can deal with the exception then deletes it.

if using pointers to dynamic data I reccomend using the set_unexpected function to ensure you delete the data incase no handler 'handles' the exception.


you could implement a static Error log that records the details of each throw, so when an exception occours you can use something like

throw MyErrorLog += "This error information.";

There could be any number of reasons, these are just examples of what i have used.

Also implementations may limit the use, aggregate structures that cannot have their contents copied due to the semantics of the data can't be passed by value ( compiler wont stop you though ).

CRT objects can't be accessed correctly across boundaries that aren't linked staticly with different versions. ( could be wrong but I remember I had issues once ).
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900