tailieunhanh - WORKING WITH ERRORS

Khái niệm cơ bản của làm việc với ngoại lệ đúng cách có thể thực hiện xử lý các trường hợp ngoại lệ bởi sự hiểu biết những điều cơ bản của trường hợp ngoại lệ được xử lý trong dòng chảy của mã của bạn. Các vấn đề cơ bản của dòng chảy ngoại lệ như sau: Khi một ngoại lệ xảy ra, ngoại lệ được thông qua ngăn xếp và mỗi khối bắt được cho cơ hội để xử lý các trường hợp ngoại lệ. Để được đánh bắt bởi khối catch tương tự của thủ tục, trường. | 15 WORKING WITH ERRORS Basics of Working with Exceptions You can properly implement exception handling by understanding the basics of how exceptions are handled in the flow of your code. The basics of exception flow are the following When an exception occurs the exception is passed up the stack and each catch block is given the opportunity to handle the exception. To be caught by the same catch block of the procedure the exception must be thrown within a try block of that procedure otherwise the exception is raise up the stack to the next catch block. The order of catch statements is important. You need to place catch blocks targeted to specific exceptions before a general exception catch block or the compiler will issue an error. The proper catch block is determined by matching the type of the exception to the name of the exception specified in the catch block. If there is no specific catch block then the exception is caught by a general catch block if one exists. To aid the troubleshooting process of the current developer or any other developers that use your code you can write error information that is as detailed as possible and targeted to a developer. Also make sure that you cleanup intermediate results when throwing an exception. Your callers will assume that you threw the exception back through the stack after you resolved the error for example rolling back database changes . Exception Handling Model You can safely run code in the CLR by creating code to control executionflow Thebasic strorture of programs that handle exceptions. The runtime has an hesi bl cksof code for the C syntax are in the exception handling model that uses protected blocks of following sample try Run code that has the potential to throw exceptions catch Exception e Run code that will generically handle the caught exception finally Run cleanup code runs with or without exception occurring 275 C THROWING AN EXCEPTION You can pass error information back to a calling client with .

TỪ KHÓA LIÊN QUAN