• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

compiletime exceptions

 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All non-runtime exceptions are called checked exceptions.If we don't provide try catch block while compiling the prgram for below code.It will throw an compile time error.



Error



If i provide try-catch block for the code .If the file does not exist then it throws FileNotFoundException is thrown.

If we are not providing try-catch block as we are supposed to be then we get error at the compile time.If we are providing try-catch block
if file does not exists we get an exception as FileNotFound Exception.Because it checked exception.

Recently i gave an interview for java and i was asked

Q1 )"What is CompileTimeException?"
But there no compiletime exceptions in java.Suppose if your are not providing try-catch block for the methods which possiably throw an exception.then we will get error.
whether file exist or not it will checked at Runtime.All runtime and non-rutime exceptions are checked at runtime only.

If i am wrong Please tell me what is compile time exceptions in java?



 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think what your interviewer was trying to ask was if you knew what checked exceptions are. I guess they expected you to answer that they (the exceptions) need to be caught or thrown. They need to be handled in some way.

Is this question related to the SCJP or a job interview that you had ?
 
Satyajeet Kadam
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think word compile used very wrongly.Everthing in java, whether it checked or unchecked excptions it checks at runtime only.For checked exceptions you are handling them or declaring them.For unchecked they is not need for try catch block.They occur because of the logical error.

Please move this forum it was job related questions.I was doutfull where should i post it in SCJP or Java General.
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using Windows ?

I think the problem is in line 1 of your posted code.

Try to use this:

 
Ranch Hand
Posts: 147
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[nevermind this post]
 
Deepak Bala
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rodrigo Tassini wrote:Are you using Windows ?

I think the problem is in line 1 of your posted code.

Try to use this:



The OP has no problems escaping characters in his source code.
 
Ranch Hand
Posts: 198
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I think word compile used very wrongly.Everthing in java, whether it checked or unchecked excptions it checks at runtime only



Checked exceptions are checked by the compiler at the time of comilation. So, you get these errors at compile time. So they called as Compiletime Exceptions.
Runtime exceptions will occur at the time of execution/running. So, they are Runtime Exceptions.

If you donot handle compile time exceptions, the code will not be compiled and .class file will not be generated. So, there is no question of running.

Understand the difference between compilation and execution.

User can overcome from Checked exceptions. As in your example if the user get FileNotFoundException, he can check with the location and make sure to keep the file over there.
User cannot overcome from UnChecked exceptions.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


this code working fine if specified file is already exists.

"CompileTimeException"- there is no such type of concept in java. The Exceptions wich are checked by compiler for smooth execution of the program at runtime is called checked exception. Whether the Exception is checked or uncheked it always occured at runtime only there is no chance of occuring at compile time

But in the program if there is any chance of raising checked exception ex:IOException, InterruptedException( generally raised when we are using Files concept and Thread.sleep() etc) compiler wont accept that code, we must handle that code by using either "try, catch" or "throws" keyword
 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 198
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Exceptions wich are checked by compiler for smooth execution of the program at runtime is called checked exception



In JDBC all the SQL exceptions are checked exceptions.

Now, In Spring all the SQL Exceptions are unchecked exceptions.

Do you think spring does not have smooth execution of program at runtime (having converted checked exceptions into unchecked exception...)??
 
satish varma
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In JDBC all the SQL exceptions are checked exceptions.

Now, In Spring all the SQL Exceptions are unchecked exceptions.

Do you think spring does not have smooth execution of program at runtime (having converted checked exceptions into unchecked exception...)??



even though there also exceptions raised at runtime only right??
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Prabhakar Reddy Bokka wrote:

Exceptions wich are checked by compiler for smooth execution of the program at runtime is called checked exception



In JDBC all the SQL exceptions are checked exceptions.

Now, In Spring all the SQL Exceptions are unchecked exceptions.

Do you think spring does not have smooth execution of program at runtime (having converted checked exceptions into unchecked exception...)??



As Spring puts some wrappers around every SQL-execution and "softens" checked to unchecked exceptions a Spring app will show stacktraces when something fails. You as a programmer don't have to handle the original exception and may focus on your business methods. In case of an exception you have to inform the user like you would do when not using Spring. Spring frees you of technically driven exceptions like SQLExceptions. (If thats a good way is to be discussed...)
 
Prabhakar Reddy Bokka
Ranch Hand
Posts: 198
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christian Dillinger wrote:

As Spring puts some wrappers around every SQL-execution and "softens" checked to unchecked exceptions a Spring app will show stacktraces when something fails. You as a programmer don't have to handle the original exception and may focus on your business methods. In case of an exception you have to inform the user like you would do when not using Spring. Spring frees you of technically driven exceptions like SQLExceptions. (If thats a good way is to be discussed...)



Even the runtime exceptions will show you the stack trace normally... I dont think spring provides something like "softens". Ofcource spring provides a meaningful exceptions for different exceptions occured at database end.

Normally user will not be able to do anything when some database exception occurs. The ideas is "when user does not recovered from that, why do we make it as a checked exception??" So, they converted to unchecked exceptions.

The compile-time checking for the presence of exception handlers is designed to reduce the number of exceptions which are not properly handled.

Check the sun tutorial for exceptions webpage
 
reply
    Bookmark Topic Watch Topic
  • New Topic