• Post Reply Bookmark Topic Watch Topic
  • New Topic

how it working?  RSS feed

 
Rd Dari
Ranch Hand
Posts: 214
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all rancher I made a custom exception .

and I used these classes but I want to understand the flow of the code: it is below:














Please help me to understand this flow:

Thanks in advanced!!
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you ran the code ? Which bit of what happened do you not understand ?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You throw the exception, you catch the exception, you print it out. I think you need to be a bit more specific about which part you don't understand.
 
Rd Dari
Ranch Hand
Posts: 214
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stuart,

Its running perfectly but I want to know its internally process that means how we decides this type of Exception.
Out put of this program: --- practice.other.MyCustomException: Welcome to you

Thank you for your reply
 
R. Jain
Ranch Hand
Posts: 375
1
Java Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rd Dari wrote:Hi Stuart,

Its running perfectly but I want to know its internally process that means how we decides this type of Exception.
Out put of this program: --- practice.other.MyCustomException: Welcome to you

Thank you for your reply


Let me demonstrate the Custom Exception in a different scenario....

Suppose you are developing a Bank Application.. When a person withdraws money, he has to enter only numeric value..
Now what if he enters a String value... After all he is a general user....
Of course, it will throw NumberFormatException..

But, rather than throwing the pre-defined exception, you can create your own, to give custom exception message to user according to your use.....
So, you will do it this way: -



So, what exactly is happening here is: - First Integer.parseInt() throws an IllegalArgumentException.... It reaches the catch block....
You could have written e.printStackTrace() there, but rather you threw another exception just like use throw pre-defined exception (throw new Exception())...
When you say throw new InvalidArgumentException("exception")... The constructor for that class is called which in turn calls its super class constructor....
So, you can say that, Custom Exception where included in Java, so as to help you make some unwanted situation in your program an exception and stop your execution there only...

 
Rd Dari
Ranch Hand
Posts: 214
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi R.Jain

Thanks for a good reply

All of you thank you.........
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!