• Post Reply Bookmark Topic Watch Topic
  • New Topic

use of throw and throws  RSS feed

 
sparsh khandelwal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone,
i have tried this program ,
but not getting the fact that why this "device error" not printed ?
please help
ScreenShot003.jpg
[Thumbnail for ScreenShot003.jpg]
 
Junilu Lacar
Sheriff
Posts: 11490
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you expecting it to be printed? Also, please QuoteYourSources (←click) -- the program examples that you've cited in your last couple of posts don't seem like they're the best ones to learn from.
 
sparsh khandelwal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:Why are you expecting it to be printed? .

as we use throw , i thought that it is a user defined exception and it should be printed when we call that function.
Also, please QuoteYourSources (←click) -- the program examples that you've cited in your last couple of posts don't seem like they're the best ones to learn from

i will reply with code as soon as possible
 
sparsh khandelwal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is the link
trying to learn from this
 
Junilu Lacar
Sheriff
Posts: 11490
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sparsh khandelwal wrote:
as we use throw , i thought that it is a user defined exception and it should be printed when we call that function.

In your example code, the exception being thrown is NOT a user-defined exception, it's an exception defined in the standard Java library. Again, why are expecting that it should be printed when the exception is thrown? What specific line of code are you expecting will print the exception?
 
Junilu Lacar
Sheriff
Posts: 11490
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sparsh khandelwal wrote:trying to learn from this

That's not a good place to learn from. Just on that page alone, there are a number of statements that are debatable and examples are wrong or misleading. The explanations are amateurish at best. Why don't you start with the official Java Tutorials?
 
sparsh khandelwal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:
sparsh khandelwal wrote:
as we use throw , i thought that it is a user defined exception and it should be printed when we call that function.

In your example code, the exception being thrown is NOT a user-defined exception, it's an exception defined in the standard Java library. Again, why are expecting that it should be printed when the exception is thrown? What specific line of code are you expecting will print the exception?

what i thought that if there is user defined exception then we use throw , otherwise throws
correct me if i am wrong
 
sparsh khandelwal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:
sparsh khandelwal wrote:trying to learn from this

That's not a good place to learn from. Just on that page alone, there are a number of statements that are debatable and examples are wrong or misleading. The explanations are amateurish at best. Why don't you start with the official Java Tutorials?

because i want to brush up all the concept as soon as possible , preparing for interview , going through all the official tutorial will lead a huge time
give me some better link to prepare for interview if you have
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sparsh khandelwal wrote:
Junilu Lacar wrote:
That's not a good place to learn from. Just on that page alone, there are a number of statements that are debatable and examples are wrong or misleading. The explanations are amateurish at best. Why don't you start with the official Java Tutorials?

because i want to brush up all the concept as soon as possible , preparing for interview , going through all the official tutorial will lead a huge time
give me some better link to prepare for interview if you have


No offense, but I read your response as... "It is more important to complete preparation for the interview, even if it means that it will be prepared with wrong or misleading technical information". Surely, you don't mean that right?

Henry
 
sparsh khandelwal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks,
yups henry , i want to prepare well , can you guide me with some good link so that i can prepare at fast speed
 
Junilu Lacar
Sheriff
Posts: 11490
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sparsh khandelwal wrote:because i want to brush up all the concept as soon as possible , preparing for interview , going through all the official tutorial will lead a huge time
give me some better link to prepare for interview if you have

That's almost the same as cramming for a driver's license test just so you can start driving, without the benefit of proper instruction on how to drive a car. If you're going to be a professional developer, then be professional about learning the skills you need to do your job properly. Learning takes time, don't rush it; otherwise, you'll only end up hurting yourself and/or others.
 
Junilu Lacar
Sheriff
Posts: 11490
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sparsh khandelwal wrote:
what i thought that if there is user defined exception then we use throw , otherwise throws
correct me if i am wrong

That is incorrect. Go to the http://docs.oracle.com/javase/tutorial/essential/exceptions/index.html to learn about exceptions from the official documentation.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sparsh khandelwal wrote:
yups henry , i want to prepare well , can you guide me with some good link so that i can prepare at fast speed



There is a famous quote... "You can have good, fast, and cheap -- pick any two". If you want to prepare well, and you want it fast, perhaps you should consider hiring a tutor. I doubt any free websites are available for this.

Henry
 
Junilu Lacar
Sheriff
Posts: 11490
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How fast and how well you can prepare depends primarily upon your ability to understand and learn. The quantity and quality of the material you use to learn is secondary. Where I come from, we have a saying that goes something like "Your eyes can eat a lot more than your mouth and stomach can actually handle." So again, I suggest that you don't try to rush the learning process. Take the time to digest the study material properly.
 
sparsh khandelwal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your guidelines henry and jinulu , i will come back when i face some problem,
and will prepare only from oracle site
 
Campbell Ritchie
Marshal
Posts: 56541
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote: . . . "You can have good, fast, and cheap -- pick any two". . . .
But what you got from that other website was potentially bad.

The analogy of driving is apposite; lots of novice drivers who have not been taught very well kill their fellow‑people. And please don’t anybody go round saying you can’t kill people with bad programming, because I am quite sure you can.
 
Junilu Lacar
Sheriff
Posts: 11490
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:And please don’t anybody go round saying you can’t kill people with bad programming, because I am quite sure you can.

As this page shows: http://www.cs.tau.ac.il/~nachumd/horror.html
 
sparsh khandelwal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so we use throw just to raise an exception ?
right ?
but still device error not printed , not able to understand that
please help
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sparsh khandelwal wrote:so we use throw just to raise an exception ?
right ?


Yes, the purpose of the "throw" command is to raise an exception.

but still device error not printed , not able to understand that
please help


Well, if I understand that blurry screenshot correctly, first you throw the "device error" exception, and then you catch it and print some other message. Of course it's hard to tell "m" from "n" in the screenshot, so I could be wrong. I suggest you take a couple of minutes to learn how to copy and paste, so you can post readable questions in future.
 
Junilu Lacar
Sheriff
Posts: 11490
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sparsh khandelwal wrote:so we use throw just to raise an exception ?
right ?
but still device error not printed , not able to understand that
please help

I ask you again, in the sample code that you gave, which specific line of code did you expect would print the exception? You haven't answered that question yet. When you answer this question, then you might realize what the answer to your own question is.
 
sparsh khandelwal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i thought it should print device error
 
Junilu Lacar
Sheriff
Posts: 11490
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sparsh khandelwal wrote:
i thought it should print device error

Therefore... throw does not print anything. The act of throwing an exception does not output anything to the console. You may be confused by what you see when an exception is not handled and propagates all the way back through the call stack. That's different. Experiment a little bit and try to throw an exception without handling it anywhere.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!