Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why Exception object's constructor is called instead of toString()?  RSS feed

 
vijayk kumar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why an Exception Object's constructor is called when I invoke an
ExceptionObject.toString() eventhough I have not defined toString() method?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All classes have a toString() method because the Object class is the ultimate parent of all classes and Object has a toString() method.

I'm not sure what you mean by
an Exception Object's constructor is called when I invoke an
ExceptionObject.toString()

Maybe if you post some code that shows this happening, it may be clearer.
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vijayk kumar:
Why an Exception Object's constructor is called when I invoke an
ExceptionObject.toString() eventhough I have not defined toString() method?


Object declares toString and all classes extend Object either implicitly or explicitly and consequently every object has a toString method.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!