java - why does the toString method shows error? -


this code. have overridden tostring() method. so, when object e being printed overridden method must called. don't see method being called.

public static void main(string[] args) {          try         {             string name="foo";             int =integer.parseint(name);         }catch (numberformatexception e)         {             system.out.println(e);         }      }     public string tostring()     {         return "err";     }  } 

you have overridden tostring on whatever class have made. writing system.out.println(e); implicitly invoke tostring method on numberformatexception class, not on class.

why attempting override tostring on numberformatexception, anyway? what's wrong system.out.println(e.getmessage()); or e.printstacktrace();?


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -