Added null check
Added exception message.