Implemented try-catch

Used the preferred technique in using the try-catch for the IOException
than just throwing it main.