• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding Throwable

 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i write throw new Throwable(),it is working.I wonder how we can write new in front of an interface because Throwable has no constructor,so how it is possible.Any comments.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Throwable isn't an interface, it's a class.

You are correct in your idea that you cannot instantiate an interface directly. But this is not relevant to Throwable, as it's a class.

Note that you should never instantiate Throwable directly, in any real application. It is legal Java to do so, but very bad practice. You should only instantiate Exception, RuntimeException or Error, or (better) their subclasses.
 
Majid Al-Fifi
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also thought Throwable is an Interface.

regards,
Majid
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic