wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Handling own Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Handling own Exceptions" Watch "Handling own Exceptions" New topic
Author

Handling own Exceptions

Abubacker Siddik
Ranch Hand

Joined: Aug 12, 2009
Posts: 90
Hi, Im new to coderanch. I want to know.. can we throw an exception class which is abstract??
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
Welcome to JavaRanch

The answer is, yes of course you can.
The answer is, no of course you can't.

Have you tried it? What happened? That is the sort of thing we have never tried, so we don't know whether it would work.
Abubacker Siddik
Ranch Hand

Joined: Aug 12, 2009
Posts: 90
ya i know we can instantiate an abstract class but when we handle own exceptions, we cant throw an abstract class as an exception class. thats you mean.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
The situation is exactly the same for all classes. You can instantiate an abstract class as an anonymous class, and then use that instance. That applies to all classes, including Exceptions.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
If you don't write an anonymous class, then you can't instantiate an abstract class. That applies to all kinds of class, including Exceptions.
Abubacker Siddik
Ranch Hand

Joined: Aug 12, 2009
Posts: 90
thanks dude, I understood things well now.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39834
    
  28
 
 
subject: Handling own Exceptions