• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

a question about exceptions

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I can't create a "ScaryException" from this code:


Can anyone explain to me why i can't create it?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean that you can't create a ScrayException? Do you get an error? What actually happens?

(note that the code you posted wouldn't actually cause a ScaryException because you pass "no" into doRisky(), and only "yes" causes the ScaryException to occur).
 
Marshal
Posts: 64693
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is your ScaryException class?

Learn about exceptions: have a look at the Java™ Tutorials section.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you let your "String test" and doRisky() method take a command line value, in that sense, you can vary the argument you pass to the doRisky() method to either "yes" , "no" or whatever very easily

String test = args[0];

...... doRisky(args[0]){}
 
ahmad mayahi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Error is:
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

ahmad mayahi wrote:Hi
Error is:



Did you import ScaryException Class in your program.
 
ahmad mayahi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you import ScaryException Class in your program.

Sorry. What do you mean "import"? Should i import the class? :S
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What do you mean "import"? Should i import the class? :S



yes , whats your doubt ? Is it in the package ? if not you cant . add them to package. Or else the dumb way is to place both java files ( ScaryException and Testing class ) in to the same location.
 
ahmad mayahi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to create the ScaryException then i can catch it. Right?
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Dint you create it yet ? Campbell has already given the link Creating Exception classes
 
ahmad mayahi
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is good
Thanks for you help
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!