tailieunhanh - Essential C# 3.0 FOR NET FRAMEWORK 3.5 PHẦN 6

Một đặc tính quan trọng của giao diện là họ không bao giờ có thể được khởi tạo, bạn có thể không sử dụng mới để tạo ra một giao diện, và do đó, giao diện có thể thậm chí không có nhà thầu hoặc finalizers. Trường hợp giao diện chỉ có sẵn từ các loại thực hiện chúng. | 390 Chapter 10 Exception Handling The code for throwing any exception is simply to prefix the exception instance with the keyword throw. The type of exception used is obviously the type that best describes the circumstances surrounding the error that caused the exception. For example consider the method in Listing . Listing Throwing an Exception public sealed class TextNumberParser public static int Parse string textDigit string digitTexts zero one two three four five six seven eight nine int result digitTexts if result 0 throw new ArgumentException The argument did not represent a digit textDigit return result Instead of throwing it is more appropriate to throw ArgumentException because the type itself indicates what went wrong and includes special parameters for identifying which parameter was at fault. Two similar exceptions are ArgumentNullException and NullReferenceException. ArgumentNullException should be thrown for the inappropriate passing of null arguments. This is a special case of an invalid parameter exception that would more generally when it wasn t null be thrown as an ArgumentException or an ArgumentOutOfRangeException. NullReferenceException is generally something that only the underlying runtime will throw with an attempt to dereference a null value to call a member on an object whose value is null. Instead of causing a NullReferenceException programmers should check parameters for null before Catching Exceptions 391 accessing them and then throw an ArgumentNullException which can provide more contextual information such as the parameter name. Catching Exceptions Throwing a particular exception type enables the type itself to identify the problem. It is not necessary in other words to catch the exception and use a switch statement on the exception message to determine what action to take in light of the exception. Instead C allows for multiple catch blocks each .

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã 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.