aspose file tools*
The moose likes Beginning Java and the fly likes Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception" Watch "Exception" New topic
Author

Exception

Mauro Trevigno
Ranch Hand

Joined: Aug 27, 2012
Posts: 39

Hi guys,

Im catching the exception and I want to print a more specific exception, its this possible?

Because if i fo to java.lang.Exception, we have a lot of subclasses:
ex.
AclNotFoundException, ActivationException, AlreadyBoundException, ApplicationException, AWTException, BackingStoreException, BadLocationException, CertificateException.





Thanks.

Regards,
-M
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Im catching the exception and I want to print a more specific exception, its this possible?

Yes. If no exception class from the API suits your needs, you can make your own class by extending java.lang.Exception and throw an instance of it.


[My Blog]
All roads lead to JavaRanch
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Mauro Trevigno wrote:Im catching the exception and I want to print a more specific exception, its this possible?

It depends what you mean by that. Your print statement will print whatever the exception really is, regardless of what you catch it as.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
Don't get me started about those stupid light bulbs.
 
subject: Exception
 
Similar Threads
exceptions
throws Error
ExamLab Exception
Nested Try/Catch
Exception Doubt