Results 1 to 2 of 2

Thread: Why do some methods throw exceptions

  1. #1
    Junior Member
    Join Date
    Jul 2007
    Answers
    1

    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.


  2. #2
    Junior Member
    Join Date
    Jul 2007
    Answers
    4

    Re: Why do some methods throw exceptions

    Quote Originally Posted by GIRISH PATEL View Post
    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.


    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact