• Post Reply Bookmark Topic Watch Topic
  • New Topic

Try Catch Finally  RSS feed

 
Stribor Kab
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created simple class that for banking account and I wanted to create my own exception class. I have couple questions...

Why does each custom exception tutorial online has 2 constructors? One is parameterless while the other has a String as a parameter?


    




If I declare that method throws my exception and then i have something like .....

    

 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The parameterless Class is specific, you cannot change the message.

The parametered Class is a general use; one that you can invoke anywhere and just have to add your message.
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[finally block] tutorial and docs say that it is usually clean up code. What exactly that is in the most applications? Could I ask user here to enter different value?

The finally block is often used to release resources, although there is now a new form of the try/catch that will automatically close a file.  You would not use the finally block to get user input; use a loop to do that.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!