• 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

compile time exception

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
i have a confusion...i am a beginner in Java . please tell ..do we have compile time exceptions.....actually all kinds of exceptions i came across come at runtime...namely noclassdeffound, arithmatic,classcast etc etc
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
'exceptions' do not occur at compile time. exceptions are pretty much defined as 'something you didn't expect to happen while your code is running happens'.

You can get errors when you compile. There are syntax errors where you spell things wrong, like 'fore' instead of 'for', or mis-matched brackets/parenes.

There are also things called 'checked exceptions'. If a method can throw a checked exception, and you don't handle it in your code, you will get an error. The exception itself doesn't happen - you have an error in your code for not dealing with something that is required.
 
YogeshGyanPrakash Gupta
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fred rosenberger wrote:'exceptions' do not occur at compile time. exceptions are pretty much defined as 'something you didn't expect to happen while your code is running happens'.

You can get errors when you compile. There are syntax errors where you spell things wrong, like 'fore' instead of 'for', or mis-matched brackets/parenes.

There are also things called 'checked exceptions'. If a method can throw a checked exception, and you don't handle it in your code, you will get an error. The exception itself doesn't happen - you have an error in your code for not dealing with something that is required.






What does Checked Exceptions actually means? Does JVM checks them ? If all exceptions come at runtime then why we have a different class of Runtime Exception ? I know Runtime exceptions are unchecked exception...
 
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, checked exceptions are checked by the compiler, not the JVM. The compiler checks that if some code can throw a checked exception, either it is handled (in a try/catch block) or declared (in a throws clause by the enclosing method.)
 
YogeshGyanPrakash Gupta
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ruben Soto wrote:Actually, checked exceptions are checked by the compiler, not the JVM. The compiler checks that if some code can throw a checked exception, either it is handled (in a try/catch block) or declared (in a throws clause by the enclosing method.)


Thanks to Both of you. My doubt got cleared. Feeling better now !
 
What does a metric clock look like? I bet it is nothing like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic