| Author |
What does catch(...) does in C++?
|
k. mahesh kumar
Greenhorn
Joined: Oct 19, 2010
Posts: 5
|
|
Please post your Reply. Thanks in advance
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
|
Catches everything.
|
[My Blog]
All roads lead to JavaRanch
|
 |
k. mahesh kumar
Greenhorn
Joined: Oct 19, 2010
Posts: 5
|
|
|
Could you please tell me in what way it differ from catch(exception e){}
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
|
catch(MyException e) catches only exception of type MyException. catch(...) catches other exception as well.
|
 |
k. mahesh kumar
Greenhorn
Joined: Oct 19, 2010
Posts: 5
|
|
Thank you Christophe Verré
|
 |
Anand Hariharan
Rancher
Joined: Aug 22, 2006
Posts: 252
|
|
Christophe Verré wrote:catch(MyException e) catches only exception of type MyException. catch(...) catches other exception as well.
One usually catches exceptions by (const) reference. It is very rare and (when seen in production code) often questionable if one wanted to catch an exception by value. It will needlessly trigger the copy constructor of the exception object, and considering that one is trying to handle an exception, one doesn't want other things in the way that could independently raise exceptions of their own.
|
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- Antoine de Saint-Exupery
|
 |
 |
|
|
subject: What does catch(...) does in C++?
|
|
|