Hi all,
Imagine I have the methods:
public static void funcA() {...}
public static void funcB()
{
byteBuffer.wrap(someByteArray, 0, someByteArra.length);
}
IN JAVA API:
public static ByteBuffer wrap(byte[]array, int offset, int length)
{
try {
return new HeapByteBuffer(array, offset, length);
} catch (IllegalArgumentException x) {
throw new IndexOutOfBoundsException();
}
}
function chain: funcB() -> ByteBuffer.wrap()
My question is how come funcB does not need to do a try-catch block around this java api method that throws an exception. funcB compiles fine without a try-catch block. I believe the answer has to do with the fact that the java api method throws an exception BUT IS NOT DECLARED as "throws IndexOutOfBoundsException"
function chain: funcA() -> funcB() -> ByteBuffer.wrap(...)
My next question is when I DO change funcB to "funcB() throws IndexOutOfBoundsException" how come funcA doesn't need to catch funcB's thrown exception? Does the compiler dig deep and realize that ByteBuffer.wrap(...) isn't declared as "wrap() throws IndexOutOfBoundsException" so all callers don't actually need to catch anything even sub-callers (funcB in this case) actually are declared as "funcB throws IndexOutOfBoundsException"?
Sorry if that was confusing or hard to understand.
Please help.
jbu