• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to throw an exception  RSS feed

 
James Eman
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


goes to



I get an error "unreported exception java.SQLException; must be caught or declared to be thrown" how can i solve this I have taken a few basic classes but never got to exceptions.
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, since you didn't get to exceptions in your learning process yet, I think the best thing would be to go through the tutorial: Lesson: Exceptions. That may seem like a diversion from getting this code done but I think it's a good idea in the long run.
 
James Eman
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok so thats what I have right in the connect class? But how do I allow the method from the other class to use it? Am I missing something? I'm going to try to read the chapter a few more times but I should have this right?
 
Chris Barrett
Bartender
Posts: 321
24
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi James,

You'll want to work through the tutorial that Paul specified. When you throw an exception, another method needs to catch that thrown exception.
The tutorial Paul referenced explains this in detail - specifically under Catching and Handling Exceptions section.

Cheers!
Chris
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never write == true or == false or similar.
Not if (b == true)... or if (b == false)... but
if (b)... and if (!b)...
Not only is == poor style, but also it can cause nasty errors if you mistakenly write = instead.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!