Adding exceptino type detection