try-catch block for invalid resources protection added.