Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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: 9123
172
  • 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: 9123
172
  • 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: 59725
187
  • 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: 2180
46
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: 9123
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:UncheckedException, you mean?



Oops! Yes.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!