try/catch looks better (?)
trim before checking length