e martë, 12 qershor 2007

Can we write try-finally blocks without a catch block?

Yes,

Incase we want to throw some exception from the current method that would be cought later by the calling program and perform some business operation, try-finally is written w/o a catch block.

like ...

public int getInterest() throws AException{

try{

abc ...

Throw new AException();

...
}finally{

Do ... some .... clearance operation

}
}

NOTE: try block should have catch or finally block, Only try block cant work/compile.

Nuk ka komente: