exception is a run time error,then why exceptions are again classified into compile time exception and run time exception,in that case it should be run time exceptions only.please give explanation with suitable real time example

Recommended Answers

All 11 Replies

This might be a good read. There's a lot more to Exceptions then you seem to think.

especially check this part: 11.2. Compile-Time Checking of Exceptions

sir oracle is very difficult plz you give me a best answer

Well, you are asking us to answer your assignment question. stultuske has pointed out the source which would give you the answer if you read. So it is your reading assignment now.

well, I hate it to tell you, but Oracle IS the best answer. They own Java, and they're the ones responsible for the updates to the language, they are the ones who decide what is going to be in the new version(s) and how it 'll be implemented.

basically, they are the ones who know exactly how it works, and should be used (since they are the ones implementing it).

the reason why the Oracle tutorials to some is difficult, is because it is also complete. A lot of tutorials "out there" are easier and less difficult, because they leave out a lot of the technical details, which are important to know if you want to know exactly how everything works, instead of just having some code that does the trick, but might be the worst possible way to do something.

if you really want to understand it, you should try and go through the difficult things, and when you don't understand something, ask specific questions. There are a lot of people on this forum willing to help you out, and provide either more explanation, or links to articles explaining it, but asking for a complete explanation about Exceptions, while that's easy a complete chapter in a decent book, is very dificult to do, and will be just as difficult for you to read.

There's no such thing as a "compile time exception" in Java. There is no instance of that term anywhere in the Java language Specification. The compiler will check that your code handles "checked" exceptions, but all Exceptions are thrown at run time.
Maybe you are reading something written by someone who does not know correct Java terminology.

well, the compiler can throw Exceptions and crash ;)

james when FileNotFoundExceptoon is occured then our program not compile its mean it is error not Exception beacuse defination of exception is

"An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions"
this is oracle defination so with respect to this defination exception is only occured when our programe is execute. then again we clasified it two types compile time exception and runtime exception please clarify it.

Did you read my previous post???
An exception can only be thrown at run time.
There is no such thing as a "compile time exception".
Where did you read about "compile time exceptions"?

There is compile-time checking of your exception handling logic to verify that your code follows the rules of checked exception handling. If your code has clear and obvious errors in that it fails to handle checked exeptions that are declared to be thrown, then the compiler shows error messages and fails to compile your code.

For example, if you call a method that is declared to throw IOException, but your method does not catch it or declare that your method throws IOException (or parent class(es)), then you get a compile time error. Your program does not compile.

These cases are not generally considered "compile time exceptions." No exception (or Throwable) object(s) are created, thrown, caught or handled (as far as we may know or be concerned about) during this compile process. It's a compile error. Your code is invalid. It does not compile or run.

commented: Good answer, very patient! +15

Now as for actual "exceptions" or "exception objects/instances" that can be created, thrown, caught and handled at runtime, it can be most informative and educational to consider the Java Throwable class and its child classes, Error and Exception, and RuntimeException (a child of Exception). Understanding how these (and their child classes) are handled and interepreted at compile time and run time is important to understanding how exceptions work in Java.

ok thanks JeffGrigg for good explanation
ans sorry james for arguments

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.