This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception" Watch "Exception" New topic
Author

Exception

Mauro Trevigno
Ranch Hand

Joined: Aug 27, 2012
Posts: 40

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: 60822
    
  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]
 
 
subject: Exception
 
Similar Threads
Exception Doubt
ExamLab Exception
throws Error
exceptions
Nested Try/Catch