TAILIEUCHUNG - Validate Data Passed to Properties and Communicate Errors to Developers

Qua xác minh dữ liệu để tiết và Truyền đạt lỗi để phát triển Để thực hiện một lớp học mà kết thúc tốt đẹp truy cập vào một bảng, nó là rất quan trọng mà các lớp học và không phải là phát triển những người đang sử dụng các lớp bảo đảm rằng tất cả dữ liệu có giá trị trước khi viết nó cơ sở dữ liệu | Validate Data Passed to Properties and Communicate Errors to Developers To make a class that wraps up access to a table it is critical that the class-and not the developer who is using the class-makes sure that all data is valid before writing it to the database. For example in the Customers table the CustomerlD field must be five characters in length-no more no less-and of course it must be unique. Phone numbers and fax numbers must also be validated. Although we don t necessarily know how many digits are in a phone number France has eight-digit numbers Spain has nine and the . has ten we do know that only numbers and characters such as periods parentheses and hyphens are allowed. You also need to communicate with other developers when their data is not valid. It is the data class s job to make sure that invalid data doesn t make it to the database. This section presents three tasks adding code to make sure that data passed to an object matches the column properties in the database adding code that validates complex data types and business rules and communicating errors to the class s consumers. Technique First you need to pass errors back up the call stack. In Visual Basic 6 the accepted method was to use which propagates an error number and an error message. This technique is still available to Visual Basic developers but it retains all the old problems. If you aren t careful programmers who are working on different components can raise the same error numbers making error handling a potential nightmare. If you aren t careful you can end up raising the same error number in your own code. You learned how to use structured exception handling in earlier chapters but the beauty is that you can define your own exceptions as needed with almost no code. Also because exceptions have a name as opposed to a number it is far easier for developers to work with your code. Finally because exceptions are defined with a Namespace even if two projects define an .

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.