Improved error handling in TextBox