Added external exception handling in Java implementation