This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

throws and throw

 
Santosh Kumar Nayak
Ranch Hand
Posts: 141
Eclipse IDE IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Can we have throws and throw new Exception in the same method ?
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12020
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried it?
 
Santosh Kumar Nayak
Ranch Hand
Posts: 141
Eclipse IDE IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically I wanted to understand as under what circumstances shall we encounter compile time exception ?

similar to IOException ?
 
Henry Wong
author
Marshal
Pie
Posts: 20835
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Santosh Kumar Nayak wrote:Basically I wanted to understand as under what circumstances shall we encounter compile time exception ?

similar to IOException ?


First, do you know the difference between a checked exception and an unchecked exception?

Henry
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote: . . . do you know the difference between a checked exception and an unchecked exception?

Henry
It's in the Java Tutorials.
 
Santosh Kumar Nayak
Ranch Hand
Posts: 141
Eclipse IDE IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes

Checked stands for compile time exception and

Unchecked stands for run time exception.
 
Winston Gutkowski
Bartender
Pie
Posts: 9477
50
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Santosh Kumar Nayak wrote:Checked stands for compile time exception and
Unchecked stands for run time exception.

No it doesn't.

What is true is that unchecked Exceptions will not normally generate compiler (ie, syntax) errors; but that has nothing to do with how they work. ALL Exceptions are thrown at runtime.

The difference is that checked Exceptions MUST be caught or thrown - ie, code that can throw a checked Exception must be either:
(a) in a try...catch block that catches the checked Exception, or one of its parents.
(b) in a method that has a throws clause that includes the checked Exception, or one of its parents.

HIH

Winston
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Santosh Kumar Nayak wrote:Checked stands for compile time exception and
Unchecked stands for run time exception.

No.

Unchecked exceptions are any exceptions that extend java.lang.RuntimeException. But that does not mean that other exceptions are "compile time exceptions". There is no such thing as "compile time exceptions". Exceptions are always thrown when the program runs - at runtime. Exceptions in your program are never thrown when the compiler is compiling your source code (compile time). Don't let the word "Runtime" in RuntimeException confuse you.
 
Santosh Kumar Nayak
Ranch Hand
Posts: 141
Eclipse IDE IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Winston.

Actually I wanted the answer as you mentioned above.

"ALL Exceptions are thrown at runtime".

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic