1. Trang chủ
  2. » Công Nghệ Thông Tin

Chapter 6 Quick Reference

2 333 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Chapter 6 Quick Reference
Định dạng
Số trang 2
Dung lượng 7,26 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Chapter 6 Quick Reference Throw an exception Use a throw statement.. For example: throw new FormatExceptionsource; Ensure that integer arithmetic is always checked for overflow Use the c

Trang 1

Chapter 6 Quick Reference

Throw an exception

Use a throw statement For example:

throw new FormatException(source);

Ensure that integer arithmetic is

always checked for overflow

Use the checked keyword For example:

int number = Int32.MaxValue;

checked {

number++;

}

Catch a specific exception

Write a catch handler that catches the specific exception class For example:

try {

} catch (FormatException fEx) {

}

Catch all exceptions in a single

catch handler

Write a catch handler that catches Exception For example:

try {

} catch (Exception ex) {

}

Ensure that some code will always

be run, even if an exception is

thrown

Write the code inside a finally block For example: try

{

}

Trang 2

To Do this

finally { // always run }

Ngày đăng: 20/10/2013, 15:15