File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -47,9 +47,9 @@ excerpt: 没有绝对的异常,只有人为的错误。
4747
4848   -  尽量使用内置的异常处理语句来替换`try / except ` 语句,比如`with ` 语句,`getattr ()` 方法。
4949
50-     # # 抛出异常
50+ # # 抛出异常
5151
52-    使用__raise__关键字可自主抛出一个异常 ,等同于Java和C# 中的throw;
52+    使用 raise 关键字可自主抛出一个异常 ,等同于Java和C# 中的throw;
5353
5454```python 
5555raise  NameError (" bad name!"  )
@@ -64,13 +64,13 @@ print dir(exceptions)
6464#  ['ArithmeticError', 'AssertionError'...]
6565``` 
6666
67- ## 自定义异常类型  
6867
69- 直接从Exception类继承即可。 
68+ ##  异常处理时常见的问题 
7069
71- ##异常处理时常见的问题
70+ ### 如何自定义异常类型  
71+ 直接从Exception类继承即可。
7272
73- ###Exception和BaseException
73+ ###  Exception和BaseException  
7474
7575当要捕获一个通用异常时,应该用` Exception ` 还是` BaseException ` ?以下是它们之间的继承关系。
7676
@@ -93,7 +93,7 @@ Python 本身提供了很多的语法范式简化了异常的处理,比如`for
9393
9494` with ` 语句在打开文件后会自动调用` finally ` 并关闭文件。我们在写 Python 代码时应该尽量避免在遇到这种情况时还使用try/except/finally的思维来处理。
9595
96- ``` 
96+ ``` python 
9797#  should not
9898try :
9999    f =  open (a_file)
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments