• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unreported exception

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok i hope some body can help me out here.
im getting an error,
error: unreported exception Exception; must be caught or declared to be thrown

ContactSql csql = new ContactSql(Fn2, Ln2, Add2, Ct2, St2, Zp2, Hp2, Cp2, Em2)




 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Saying throws Exception is almost always poor design. The only circumstance where it might be all right is in something indefinite which might throw an Exception when overridden, and you don’t know the type, eg the Callable#call() method. You do not know whether implemented versions will throw an exception or not, so you have to declare the non‑specific Exception.
You should declare the exact type of Exception you expect. Possibly SQLException. But why are you throwing checked exceptions from a constructor in the first place? Does anything in that constructor declare a checked Exception? Can you catch it there?
The sort of Exception you should be throwing from a constructor is this sort or this, but they are unchecked and should be shown by @throws tags in the documentation comment.

I had to break the long lines in your code because they are so difficult to read, and had to edit it again because I didn’t quite do it right first time.
 
Adam Burda
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok im still playing around with java, useing book Java for dummies. I do know SQL. So i was trying to make an app to send data to SQL server. This can be done using this code.


If you look at the main part of the app

public static void main(String[] args) throws Exception

this app works, with no problems...

Now i want to take the same app but with out the main, to use as a class file with in my panel.class

im calling the panel.class ContactP.java

and im calling the SQL app ContactSql.java

so in the ContactP.java i write ContactSql csql = new ContactSql(Fn2, Ln2, Add2, Ct2, St2, Zp2, Hp2, Cp2, Em2);

and in the ContactSql.java i write public ContactSql(String Fn2, String Ln2, String Add2, String Ct2, String St2, String Zp2, String Hp2, String Cp2, String Em2)throws Exception

but i get an error when i compile the program.

error: unreported exception Exception; must be caught or declared to be thrown
ContactSql csql = new ContactSql(Fn2, Ln2, Add2, Ct2, St2, Zp2, Hp2, Cp2, Em2);
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic