• Post Reply Bookmark Topic Watch Topic
  • New Topic

a question about exceptions  RSS feed

 
ahmad mayahi
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?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • 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).
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • 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.
 
bernard adaba
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:
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • 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 Java VI Editor
  • 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 Java VI Editor
  • 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
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!