, : a RuntimeException , ; . ( , RuntimeException Exception โ Java, .)
, . , ( ). throws Exception, Exception , throws Exception. throws โ , throws Exception, throws ParseException.
( " ( )", , , , , , , throws. )
, , : 1. , 2. main , Exception.
, () , main throws Exception:
public class CheckTest
{
public static final void main(String[] params)
{
new CheckTest().method2();
}
public void method1() throws Exception{
throw new java.text.ParseException("foo", 2);
}
public void method2() throws Exception{
this.method1();
}
}
:
CheckTest.java:27: unreported exception java.lang.Exception; must be caught or declared to be thrown
new CheckTest().method2();
^
1 error