File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes C / C++ and the fly likes What does catch(...) does in C++? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » C / C++
Bookmark "What does catch(...) does in C++?" Watch "What does catch(...) does in C++?" New topic
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: 14687
    
  16

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: 14687
    
  16

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: 257

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What does catch(...) does in C++?
 
Similar Threads
Jboss in Action question: migration from other Application Servers
How low level do YOU code ?
Need help understanding generics.
WA #2 ..... word association
Barn Burning Patterns