Tried to rework this code many times (even changed exception type in try-catch block) without any success. Please help me find the bug. Any help would be greatly appreciated.