This week's book giveaway is in the XML and Related Technologies forum.
We're giving away four copies of Java XML & JSON and have Jeff Friesen on-line!
See this thread for details.
Win a copy of Java XML & JSON this week in the XML and Related Technologies forum!
  • 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
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

When does Checked exception occur, at run time or compile time ?  RSS feed

 
Ranch Hand
Posts: 529
19
Eclipse IDE Java MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know about unchecked exception that occurs at run time but don't know about checked. I found a video says checked exception and unchecked exception occurs at run time only. Also found a website which says checked exception occurs at compile time. I use Java 8 Documentation but didn't find when checked exception occurs at compile time or at run time. If you read in Java Documentation please give me reference if possible.
 
Saloon Keeper
Posts: 9703
192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All exceptions (except those thrown by the compiler when you try to compile bad code) are always thrown at runtime. The difference between checked and unchecked (sub-classes of RuntimeException) exceptions is whether the compiler forces you to write code that handles the exception.



The compiler will throw an exception during compilation, but it's not the same exception as the one thrown in bar(). The exception thrown in bar() (after you declare that the method throws a checked exception) will still only be thrown during runtime of your application.
 
Stephan van Hulst
Saloon Keeper
Posts: 9703
192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RuntimeException really is a misnomer. They should have called it CheckedException instead.
 
Marshal
Posts: 62803
203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:RuntimeException really is a misnomer. They should have called it CheckedException instead.

UncheckedException, you mean?

The theory is that the runtime Exception occurs entirely within the Java® runtime rather than at the interface between Java® and other code. An IOException occurs when you attempt to access the hard drive or network or keyboard, for example. That is why they called in runtime Exception. At least that it the theory; most people can find exceptions to that notion.
 
Bartender
Posts: 2212
47
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One important thing.

Exceptions do not occur at compile time. Period.

A compilation error is not an Exception.
 
Ganish Patil
Ranch Hand
Posts: 529
19
Eclipse IDE Java MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Pawel

Exceptions do not occur at compile time. Period. A compilation error is not an Exception.

thats what I was trying to confirm. Thank you.
 
Stephan van Hulst
Saloon Keeper
Posts: 9703
192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:UncheckedException, you mean?



Oops! Yes.
 
There are 10 kinds of people in this world. Those that understand binary get this tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!