Why do some methods throw exceptions
Why do some methods throw exceptions and how the calling method handles those exceptions?
If the checked exceptions are thrown then what would happen?
Also if unchecked exceptions are thrown then what would happen?
How do i know my method can throw exception and i should include throws statement. Should i use throws Exception clause to each method?
Also please give me the real world example of throwing exception.
Please explain me in detail the concept of throwing exceptions using example.
Re: Why do some methods throw exceptions
[QUOTE=GIRISH PATEL;14692]Why do some methods throw exceptions and how the calling method handles those exceptions?
If the checked exceptions are thrown then what would happen?
Also if unchecked exceptions are thrown then what would happen?
How do i know my method can throw exception and i should include throws statement. Should i use throws Exception clause to each method?
Also please give me the real world example of throwing exception.
Please explain me in detail the concept of throwing exceptions using example.[/QUOTE]
See generally, if there is a probability of any occurrances that you think would occur in the program , as you write basically, while if you think there is any problem that would occur,like if an i/o exception would occur then you declare it in advance , so, that the normal flow of execution does not stop.
when you declare an i/o exception that you predict would occur in advance, then you declare it in order to handle this exception if it occurs in advance..this are nothing but checked exceptions, generally they are compile time handling exception.
note:
checked exception are nothin but you can edit your code before any exception occurs by catching or handling the exception while compiling the code, they are compile time exception.
unchecked exceptions are those even after you change the code , the code compiles fine but gives an error while running, this are run-time exceptions.they are not user specific to handle at the compile time itself.they show error only while running the code, but do not show while compiling.