A little bit about exception concept .... plz help me out....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    A little bit about exception concept .... plz help me out....

    here is my code like this ...

    void test() throws Exception
    {
    //My code
    }

    if i call this method .....

    obj_ref.test()

    if the caller does not specify any code .. like throws Exception or

    try
    {
    }catch(){}


    in this case does compiler report any error like ... unreported excepiotn

    if not why ???

    if does ..... then also why????

    i think u got my point .......

    plz help me out ...

    thanxxxx in advance
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    I don't think there will be an Unreported Exception error, but if the Exception is generated, then your program will terminate because of an Unhandled Exception. I'm not 100% sure, though.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by dmjpro
      here is my code like this ...

      void test() throws Exception
      {
      //My code
      }

      if i call this method .....

      obj_ref.test()

      if the caller does not specify any code .. like throws Exception or

      try
      {
      }catch(){}

      in this case does compiler report any error like ... unreported excepiotn

      if not why ???

      if does ..... then also why????

      i think u got my point .......

      plz help me out ...

      thanxxxx in advance
      Put it on a compiler and see what happens. Try to explain your results first then you can ask if you have any doubt.

      Comment

      • dmjpro
        Top Contributor
        • Jan 2007
        • 2476

        #4
        if i write IOException instead of Exception then what happens ......

        is the term checked and unchecked exceptions come here in this context.....

        plz expplain me in details these two terms....

        thanxxxxx

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by dmjpro
          if i write IOException instead of Exception then what happens ......

          is the term checked and unchecked exceptions come here in this context.....

          plz expplain me in details these two terms....

          thanxxxxx
          Try these things on the compiler first dj, I will only try to explain when I'm satisfied you have tried it yourself.

          Comment

          • dmjpro
            Top Contributor
            • Jan 2007
            • 2476

            #6
            i tried it myself and come to a conclusion like this .....


            if a method specifies .... throws any exception

            void test() throws any type of class inherited from Exception
            {
            }

            then if i call test then it should be handled anyway or the caller method should report .....
            the thrown exception may be checked or unchecked .. that does not any matter

            if the code of test does not throw that exception ... only then
            checked or unchecked comes up

            m i right ....

            any additional info is most welcome ...

            thanxxxx

            Comment

            Working...