• 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

what are checked and unchecked exceptions ?  RSS feed

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can any body tell me what are checked and unchecked exceptions with one simple example.
 
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have any code that might throw a checked exception, you must either enclose it in a try/catch clause that handles that potential exception, or must declare the checked exception in a throws clause in the containing method. Basically, the compiler will check that you do that with code that potentially throws checked exceptions. The compiler doesn't care about unchecked exceptions.
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

teja hyd wrote: can any body tell me what are checked and unchecked exceptions with one simple example.



check this link :Exceptions
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Checked -> Exceptions caught by compiler
unchecked -> Exceptions not caught by compiler( you can write your own catch block to catch at runtime )
 
Java Cowboy
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exceptions are never caught by the compiler, because exceptions happen at runtime, not at compile time.

Checked exceptions are exceptions that are checked by the compiler - in other words, the compiler checks to see if you handle them with a try ... catch block, or declare that you throw them further with a throws-clause in the method declaration. If you don't handle or declare a checked exception in a throws-clause, the compiler will stop with an error.

Unchecked exceptions are not checked by the compiler - you do not need to catch them or declare them with a throws-clause.
 
Put the moon back where you found it! We need it for tides and poetry and stuff. Like 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!