Danh mục tài liệu

Chapter 6 Quick Reference

Số trang: 2      Loại file: pdf      Dung lượng: 7.26 KB      Lượt xem: 16      Lượt tải: 0    
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Chương 6 Quick Reference Để Throw một ngoại lệLàm điều này sử dụng một ném tuyên bố. Ví dụ: ném FormatException mới (nguồn); Sử dụng các từ khoá kiểm tra.
Nội dung trích xuất từ tài liệu:
Chapter 6 Quick ReferenceChapter 6 Quick ReferenceTo Do this Use a throw statement. For example:Throw an exception throw new FormatException(source); Use the checked keyword. For example: int number = Int32.MaxValue;Ensure that integer arithmetic is checkedalways checked for overflow { number++; } Write a catch handler that catches the specific exception class. For example: try {Catch a specific exception ... } catch (FormatException fEx) { ... } Write a catch handler that catches Exception. For example: try {Catch all exceptions in a single ...catch handler } catch (Exception ex) { ... } Write the code inside a finally block. For example:Ensure that some code will always trybe run, even if an exception is {thrown ... }To Do this finally { // always run }