Từ khóa nâng cao Python được sử dụng để tăng ngoại lệ hoặc lỗi. Từ khóa raise phát sinh lỗi và dừng luồng điều khiển của chương trình. Nó được sử dụng để hiển thị ngoại lệ hiện tại trong một trình xử lý ngoại lệ để nó có thể được xử lý thêm trong ngăn xếp cuộc gọi
Cú pháp của từ khóa tăng
tăng {name_of_ the_ exception_class}
Cách cơ bản để gây ra một lỗi là
tăng Ngoại lệ ["văn bản người dùng"]
Ví dụ
Trong đoạn mã dưới đây, chúng tôi kiểm tra xem một số nguyên là chẵn hay lẻ. nếu số nguyên là số lẻ, một ngoại lệ được nêu ra. a là một biến mà chúng tôi đã gán một số 5, vì a là số lẻ, sau đó nếu vòng lặp kiểm tra xem đó có phải là số nguyên lẻ hay không, nếu đó là số nguyên lẻ thì sẽ xảy ra lỗi
Đầu vào
Python3
def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
3def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
4 def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
5def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
6def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
7 def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
3def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
9 def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
0 def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
1def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
4 def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
40def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
41def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
42def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
43 def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
44def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
45def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
46đầu ra
Trong khi nêu lỗi, chúng tôi cũng có thể nêu loại lỗi nào chúng tôi cần nêu và nếu cần, in ra văn bản
cú pháp.
tăng TypeError
Ví dụ
Trong đoạn mã dưới đây, chúng tôi đã thử thay đổi chuỗi 'apple' được gán cho s thành số nguyên và viết mệnh đề try-except để tăng ValueError. từ khóa nâng cao gây ra lỗi giá trị với thông báo “Chuỗi không thể thay đổi thành số nguyên”
Đầu vào
Python3
def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
47def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
4 def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
49def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
6def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
51def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
41def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
42def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
54def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
4 def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
56def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
57def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
58 def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
59def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
42def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
43 def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
62______363def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
46đầu ra
Đưa ra một ngoại lệ mà không chỉ định lớp ngoại lệ
Khi chúng tôi sử dụng từ khóa nâng cao, không bắt buộc phải đưa ra một lớp ngoại lệ cùng với nó. Khi chúng tôi không cung cấp bất kỳ tên lớp ngoại lệ nào với từ khóa nâng cao, nó sẽ kích hoạt lại ngoại lệ xảy ra lần cuối
Ví dụ
Trong đoạn mã trên, chúng tôi đã thử thay đổi chuỗi 'apple' thành số nguyên và viết mệnh đề try-ngoại trừ để tăng ValueError. Mã vẫn giống như trước ngoại trừ việc chúng tôi không cung cấp một lớp ngoại lệ, nó sẽ xác định lại ngoại lệ đã xảy ra lần cuối
Tránh tăng một
def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
0 chung chung. Để nắm bắt nó, bạn sẽ phải nắm bắt tất cả các ngoại lệ cụ thể khác phân loại nóvấn đề 1. Ẩn lỗi
raise Exception['I know Python!'] # Don't! If you catch, likely to hide bugs.
Ví dụ
def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
vấn đề 2. Sẽ không bắt
Và các sản phẩm khai thác cụ thể hơn sẽ không bắt được ngoại lệ chung
def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
Thực hành tốt nhất. def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
1 tuyên bố
def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
Thay vào đó, hãy sử dụng hàm tạo Ngoại lệ cụ thể nhất phù hợp với vấn đề của bạn về mặt ngữ nghĩa
raise ValueError['A very specific bad thing happened']
điều này cũng thuận tiện cho phép một số lượng đối số tùy ý được chuyển đến hàm tạo
raise ValueError['A very specific bad thing happened', 'foo', 'bar', 'baz']
Các đối số này được truy cập bởi thuộc tính
def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
2 trên đối tượng def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
0. Ví dụtry:
some_code_that_may_raise_our_value_error[]
except ValueError as err:
print[err.args]
bản in
raise Exception['I know Python!'] # Don't! If you catch, likely to hide bugs.
0Trong Python 2. 5, một thuộc tính thực tế của
def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
4 đã được thêm vào def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
5 để khuyến khích người dùng phân lớp Ngoại lệ và ngừng sử dụng def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
2, nhưng việc giới thiệu def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
4 và việc ngừng sử dụng các đối số ban đầu đã bị rút lạiThực hành tốt nhất. mệnh đề def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
8
def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
Ví dụ, khi bên trong một mệnh đề ngoại trừ, bạn có thể muốn ghi nhật ký rằng một loại lỗi cụ thể đã xảy ra, sau đó tăng lại. Cách tốt nhất để làm điều này trong khi vẫn giữ nguyên dấu vết ngăn xếp là sử dụng câu lệnh tăng trần. Ví dụ
raise Exception['I know Python!'] # Don't! If you catch, likely to hide bugs.
6Đừng sửa đổi lỗi của bạn. nhưng nếu bạn khăng khăng
Bạn có thể duy trì stacktrace [và giá trị lỗi] với
def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
9, nhưng cách này dễ bị lỗi hơn và có vấn đề về khả năng tương thích giữa Python 2 và 3, bạn nên sử dụng def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
1 trần để nâng cấp lạiĐể giải thích -
def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
9 trả về loại, giá trị và truy nguyêndef demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
0Đây là cú pháp trong Python 2 - lưu ý rằng cú pháp này không tương thích với Python 3
raise Exception['I know Python!'] # Don't! If you catch, likely to hide bugs.
0Nếu muốn, bạn có thể sửa đổi những gì xảy ra với mức tăng lương mới của mình - e. g. thiết lập
def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
2 mới cho ví dụraise Exception['I know Python!'] # Don't! If you catch, likely to hide bugs.
1Và chúng tôi đã bảo tồn toàn bộ truy nguyên trong khi sửa đổi các đối số. Lưu ý rằng đây không phải là cách thực hành tốt nhất và cú pháp không hợp lệ trong Python 3 [khiến việc duy trì khả năng tương thích trở nên khó khăn hơn nhiều]
raise Exception['I know Python!'] # Don't! If you catch, likely to hide bugs.
2Trong Trăn 3
raise Exception['I know Python!'] # Don't! If you catch, likely to hide bugs.
3Lần nữa. tránh thao tác theo dõi thủ công. Nó kém hiệu quả hơn và dễ bị lỗi hơn. Và nếu bạn đang sử dụng luồng và
def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
3, bạn thậm chí có thể nhận được truy nguyên sai [đặc biệt nếu bạn đang sử dụng xử lý ngoại lệ cho luồng điều khiển - điều mà cá nhân tôi có xu hướng tránh. ]Python 3, Chuỗi ngoại lệ
Trong Python 3, bạn có thể xâu chuỗi các Ngoại lệ, giúp duy trì truy nguyên
raise Exception['I know Python!'] # Don't! If you catch, likely to hide bugs.
4hãy nhận biết
- điều này cho phép thay đổi loại lỗi đã nêu và
- cái này không tương thích với Python 2
Phương pháp không dùng nữa
Chúng có thể dễ dàng ẩn và thậm chí vào mã sản xuất. Bạn muốn đưa ra một ngoại lệ và việc thực hiện chúng sẽ đưa ra một ngoại lệ, nhưng không phải là ngoại lệ dự định
Hợp lệ trong Python 2, nhưng không có trong Python 3 như sau
raise Exception['I know Python!'] # Don't! If you catch, likely to hide bugs.
5Chỉ hợp lệ trong các phiên bản Python cũ hơn nhiều [2. 4 trở xuống], bạn vẫn có thể thấy mọi người nâng dây
raise Exception['I know Python!'] # Don't! If you catch, likely to hide bugs.
6Trong tất cả các phiên bản hiện đại, điều này thực sự sẽ tăng
def demo_no_catch[]:
try:
raise Exception['general exceptions not caught by specific handling']
except ValueError as e:
print['we will not catch exception: Exception']
>>> demo_no_catch[]
Traceback [most recent call last]:
File "", line 1, in
File "", line 3, in demo_no_catch
Exception: general exceptions not caught by specific handling
4, bởi vì bạn không tăng loại def demo_bad_catch[]:
try:
raise ValueError['Represents a hidden bug, do not catch this']
raise Exception['This is the exception you expect to handle']
except Exception as error:
print['Caught this error: ' + repr[error]]
>>> demo_bad_catch[]
Caught this error: ValueError['Represents a hidden bug, do not catch this',]
5. Nếu bạn không kiểm tra đúng ngoại lệ và không có người đánh giá nào biết về vấn đề này, thì nó có thể được đưa vào sản xuấtVí dụ sử dụng
Tôi đưa ra các Ngoại lệ để cảnh báo người tiêu dùng về API của tôi nếu họ sử dụng không đúng cách
raise Exception['I know Python!'] # Don't! If you catch, likely to hide bugs.
7Tạo các loại lỗi của riêng bạn khi được đề xuất
"Tôi muốn cố tình tạo ra một lỗi để nó đi vào ngoại trừ"
Bạn có thể tạo các loại lỗi của riêng mình, nếu bạn muốn chỉ ra điều gì đó cụ thể không ổn với ứng dụng của mình, chỉ cần phân loại điểm thích hợp trong hệ thống phân cấp ngoại lệ