Added exception handling with try-catch