• 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

Exception

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
look this:



I don't understand why compiler return: "unreported exception MyException; must be caught or declared to be thrown".

But doStuff() don't caught the exception??

Thanks!!
 
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Higor Zardo:
look this:



I don't understand why compiler return: "unreported exception MyException; must be caught or declared to be thrown".

But doStuff() don't caught the exception??

Thanks!!



I saw two problem in your code:
1: class MyException extend Exception {

you know how to fix it? right..

2:
when you call doStuff method, you have declared that you might throw a checked exception..and you did..!!
try --> Exception thrown (E1)
for E1, you need to implement..."HANDLE OR THROW RULE"..!! you decided to handle it..!!
catch ---> Exception thrown (E2)
for E2,, you need to implement..."HANDLE OR THROW RULE"..!!
do something for it also..this is what compiler is asking for..!!
I hope ..i cleared you what is your problem..!! Now fix it..
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here you took care of catching the Exception in doStuff() but, you have thrown Excpetion from dostuff to caller main() which you did not take care of.and thus the error.and also the exception you have thrown from catch block must also be catched.
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The method, someMethod(), must either catch the exception or declare that it "throws" it.

Kaydell
 
Higor Zardo
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sunny Jain,
thank you very much, i understood perfectly!!

Arun Kumar Gaddam, Kaydell Leavitt,
thanks you too!!

Thanks for everybody.
reply
    Bookmark Topic Watch Topic
  • New Topic