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

Working on a try/catch block  RSS feed

 
Landon Simmons
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to setup a try / catch block
I am not sure how exactly this works but any help would be greatly appreciated.

 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The try/catch block is explained here. It basically looks like this:

Where in your code do you think you need this and why?
 
Landon Simmons
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the final step in my assignment and I am working on getting it going, just a bit confused on where to place it to make it work.
The try block is supposed to catch any duplicate subscribers by checking their addresses.
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. If you are working on the same question and are just updating your code, please post the updated code to the original thread.
 
Landon Simmons
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to setup the catch block and it's not working or I am coding it wrong.


 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you want the code to be this:

A couple of things: your new exception should extend Exception, not NewspaperSubscriber.

super("duplicate subscription") needs a ";" at the end.

And most importantly, does SevenDaySubscriber, WeekdaySubscriber, or WeekendSubscriber throw a DuplicateException in their constructors?
 
Fred Kleinschmidt
Bartender
Posts: 560
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The body of your equals() method can be greatly simplified to:


And you might want to consider using equalsIgnoreCase() instead of equals() when making the comparison.
 
Carey Brown
Bartender
Posts: 2996
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred Kleinschmidt wrote:The body of your equals() method can be greatly simplified to:


And you might want to consider using equalsIgnoreCase() instead of equals() when making the comparison.

Landon - DO NOT keep spawning new topic threads for this assignment. Continue to use the first one you started. Issues like this have already been addressed in the other thread.
 
Landon Simmons
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my bad, sorry!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!