java - What is the point in throws clause? -


i understand point of checked exceptions: remind developer of errors need aware of. understand point of not handling exceptions if cannot recover them. but why that, should decide not handle checked error, have include throws statement. if run code, runtime error, , should comment out throws statement (and add { ), compile time error. seems pointless throw error out of main() if still interrupts program.

import java.io.ioexception;  public class blah {      public static void main(string[] args)          throws ioexception {          throw new ioexception();      }  } 

the point of being able "duck" exception adding methods throws clause flexibility when creating code else going use.. maybe code gets exception, rather caller of method handle instead of handling exception yourself, allowing calling developer know happened instead of re-throwing exception or returning null value.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -