• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 529
19
Eclipse IDE MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
RuntimeException really is a misnomer. They should have called it CheckedException instead.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 MySQL Database Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:UncheckedException, you mean?



Oops! Yes.
 
reply
    Bookmark Topic Watch Topic
  • New Topic