TAILIEUCHUNG - Trying Code and Catching Exceptions

Đang cố gắng Mã và bắt ngoại lệ C # làm cho nó dễ dàng để tách mã mà thực hiện các dòng chảy chính của chương trình từ xử lý lỗi code, bằng cách sử dụng các ngoại lệ và xử lý ngoại lệ. Để viết chương trình exceptionaware, bạn cần phải làm hai việc | Trying Code and Catching Exceptions C makes it easy to separate the code that implements the main flow of the program from the error handling code by using exceptions and exception handlers. To write exception-aware programs you need to do two things 1. Write your code inside a try block try is a keyword . When the code runs it attempts to execute all the statements inside the try block and if none of the statements generates an exception they all run one after the other to completion. However if an error condition occurs execution jumps out of the try block and into a catch handler. 2. Write one or more catch handlers catch is a keyword immediately after the try block to handle any possible error conditions. If any one of the statements inside the try block causes an error the runtime generates and throws an exception. The runtime then examines the catch handlers after the try block and transfers control directly to a matching handler. Catch handlers are designed to trap particular exceptions allowing you to provide different handlers for the different errors that can happen. Here s an example that uses a try block to attempt to convert some text fields into integer values call a method to calculate a value and write the result to a text field. Converting a string to an integer requires that the string contains a valid representation and not some arbitrary sequence of characters. If the string contains invalid characters the method throws a FormatException and execution transfers to the corresponding catch handler. When the catch handler finishes the program continues with the first statement after the handler try int leftHandSide int rightHandSide int answer doCalculation leftHandSide rightHandSide catch FormatException fEx Handle the exception . Handling an Exception The catch handler uses syntax similar to that used by a method parameter to specify

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.