[{"data":1,"prerenderedAt":968},["ShallowReactive",2],{"post-2025-07-10-python":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"tags":11,"body":14,"_type":962,"_id":963,"_source":964,"_file":965,"_stem":966,"_extension":967},"\u002Fblog\u002F2025-07-10-python","blog",false,"","Python-异常处理及程序调试","Python异常处理与调试：try\u002Fexcept\u002Ffinally、自定义异常、logging与pdb调试。","2025-07-10",[12,13],"Python","基础",{"type":15,"children":16,"toc":957},"root",[17,22,29,35,207,212,226,275,323,369,393,404,445,456,476,529,543,555,569,601,606,612,625,634,654,662,683,691,704,712,724,732,745,750,836,872,885,905,919,951],{"type":18,"tag":19,"props":20,"children":21},"element","hr",{},[],{"type":18,"tag":23,"props":24,"children":26},"h3",{"id":25},"异常概念",[27],{"type":28,"value":25},"text",{"type":18,"tag":30,"props":31,"children":32},"p",{},[33],{"type":28,"value":34},"在程序运行过程中，经常会遇到各种各样的错误，这些错误统称为“异常”。如下表是Python常见的异常与描述：",{"type":18,"tag":36,"props":37,"children":38},"table",{},[39,59],{"type":18,"tag":40,"props":41,"children":42},"thead",{},[43],{"type":18,"tag":44,"props":45,"children":46},"tr",{},[47,54],{"type":18,"tag":48,"props":49,"children":51},"th",{"align":50},"center",[52],{"type":28,"value":53},"异常",{"type":18,"tag":48,"props":55,"children":56},{},[57],{"type":28,"value":58},"描述",{"type":18,"tag":60,"props":61,"children":62},"tbody",{},[63,77,90,103,116,129,142,155,168,181,194],{"type":18,"tag":44,"props":64,"children":65},{},[66,72],{"type":18,"tag":67,"props":68,"children":69},"td",{"align":50},[70],{"type":28,"value":71},"NameError",{"type":18,"tag":67,"props":73,"children":74},{},[75],{"type":28,"value":76},"尝试访问一个未声明的变量引发错误",{"type":18,"tag":44,"props":78,"children":79},{},[80,85],{"type":18,"tag":67,"props":81,"children":82},{"align":50},[83],{"type":28,"value":84},"IndexError",{"type":18,"tag":67,"props":86,"children":87},{},[88],{"type":28,"value":89},"索引超出序列范围引发错误",{"type":18,"tag":44,"props":91,"children":92},{},[93,98],{"type":18,"tag":67,"props":94,"children":95},{"align":50},[96],{"type":28,"value":97},"IndentationError",{"type":18,"tag":67,"props":99,"children":100},{},[101],{"type":28,"value":102},"缩进错误",{"type":18,"tag":44,"props":104,"children":105},{},[106,111],{"type":18,"tag":67,"props":107,"children":108},{"align":50},[109],{"type":28,"value":110},"ValueError",{"type":18,"tag":67,"props":112,"children":113},{},[114],{"type":28,"value":115},"传入的值错误",{"type":18,"tag":44,"props":117,"children":118},{},[119,124],{"type":18,"tag":67,"props":120,"children":121},{"align":50},[122],{"type":28,"value":123},"KeyError",{"type":18,"tag":67,"props":125,"children":126},{},[127],{"type":28,"value":128},"请求一个不存在的字典关键字引发的错误",{"type":18,"tag":44,"props":130,"children":131},{},[132,137],{"type":18,"tag":67,"props":133,"children":134},{"align":50},[135],{"type":28,"value":136},"IOError",{"type":18,"tag":67,"props":138,"children":139},{},[140],{"type":28,"value":141},"输入输出错误（如要读取的文件不存在）",{"type":18,"tag":44,"props":143,"children":144},{},[145,150],{"type":18,"tag":67,"props":146,"children":147},{"align":50},[148],{"type":28,"value":149},"ImportError",{"type":18,"tag":67,"props":151,"children":152},{},[153],{"type":28,"value":154},"当import语句无法找到模块引发的错误",{"type":18,"tag":44,"props":156,"children":157},{},[158,163],{"type":18,"tag":67,"props":159,"children":160},{"align":50},[161],{"type":28,"value":162},"AttributeError",{"type":18,"tag":67,"props":164,"children":165},{},[166],{"type":28,"value":167},"当尝试访问位置的对象属性时，引发的错误",{"type":18,"tag":44,"props":169,"children":170},{},[171,176],{"type":18,"tag":67,"props":172,"children":173},{"align":50},[174],{"type":28,"value":175},"TypeError",{"type":18,"tag":67,"props":177,"children":178},{},[179],{"type":28,"value":180},"类型不合适引发的错误",{"type":18,"tag":44,"props":182,"children":183},{},[184,189],{"type":18,"tag":67,"props":185,"children":186},{"align":50},[187],{"type":28,"value":188},"MemoryError",{"type":18,"tag":67,"props":190,"children":191},{},[192],{"type":28,"value":193},"内存不足",{"type":18,"tag":44,"props":195,"children":196},{},[197,202],{"type":18,"tag":67,"props":198,"children":199},{"align":50},[200],{"type":28,"value":201},"ZeroDivisionError",{"type":18,"tag":67,"props":203,"children":204},{},[205],{"type":28,"value":206},"当除数为0时引发的错误",{"type":18,"tag":23,"props":208,"children":210},{"id":209},"异常处理语句",[211],{"type":28,"value":209},{"type":18,"tag":213,"props":214,"children":216},"h4",{"id":215},"tryexcept-语句",[217,224],{"type":18,"tag":218,"props":219,"children":221},"code",{"className":220},[],[222],{"type":28,"value":223},"try...except",{"type":28,"value":225}," 语句",{"type":18,"tag":30,"props":227,"children":228},{},[229,231,236,238,244,246,252,254,259,261,266,268,273],{"type":28,"value":230},"使用",{"type":18,"tag":218,"props":232,"children":234},{"className":233},[],[235],{"type":28,"value":223},{"type":28,"value":237},"语捕获并处理异常时，把可能产生异常的代码放在",{"type":18,"tag":218,"props":239,"children":241},{"className":240},[],[242],{"type":28,"value":243},"try",{"type":28,"value":245},"语句块中，把处理结果放在",{"type":18,"tag":218,"props":247,"children":249},{"className":248},[],[250],{"type":28,"value":251},"except",{"type":28,"value":253},"语句块中：若",{"type":18,"tag":218,"props":255,"children":257},{"className":256},[],[258],{"type":28,"value":243},{"type":28,"value":260},"执行时出现错误，将会执行",{"type":18,"tag":218,"props":262,"children":264},{"className":263},[],[265],{"type":28,"value":251},{"type":28,"value":267},"语句块，否则将不执行",{"type":18,"tag":218,"props":269,"children":271},{"className":270},[],[272],{"type":28,"value":251},{"type":28,"value":274},"语句块，语法结构如下：",{"type":18,"tag":276,"props":277,"children":281},"pre",{"className":278,"code":279,"language":280,"meta":7,"style":7},"language-python shiki shiki-themes github-dark","try:\n    block1\nexcept [ExceptionName [as alias]]:\n    block2\n","python",[282],{"type":18,"tag":218,"props":283,"children":284},{"__ignoreMap":7},[285,296,305,314],{"type":18,"tag":286,"props":287,"children":290},"span",{"class":288,"line":289},"line",1,[291],{"type":18,"tag":286,"props":292,"children":293},{},[294],{"type":28,"value":295},"try:\n",{"type":18,"tag":286,"props":297,"children":299},{"class":288,"line":298},2,[300],{"type":18,"tag":286,"props":301,"children":302},{},[303],{"type":28,"value":304},"    block1\n",{"type":18,"tag":286,"props":306,"children":308},{"class":288,"line":307},3,[309],{"type":18,"tag":286,"props":310,"children":311},{},[312],{"type":28,"value":313},"except [ExceptionName [as alias]]:\n",{"type":18,"tag":286,"props":315,"children":317},{"class":288,"line":316},4,[318],{"type":18,"tag":286,"props":319,"children":320},{},[321],{"type":28,"value":322},"    block2\n",{"type":18,"tag":324,"props":325,"children":326},"ul",{},[327,339,358],{"type":18,"tag":328,"props":329,"children":330},"li",{},[331,337],{"type":18,"tag":218,"props":332,"children":334},{"className":333},[],[335],{"type":28,"value":336},"block1",{"type":28,"value":338},"：表示可能报错的代码块",{"type":18,"tag":328,"props":340,"children":341},{},[342,348,350,356],{"type":18,"tag":218,"props":343,"children":345},{"className":344},[],[346],{"type":28,"value":347},"ExceptionName [as alias]",{"type":28,"value":349},"：可选参数，用于指定要捕获的异常。",{"type":18,"tag":218,"props":351,"children":353},{"className":352},[],[354],{"type":28,"value":355},"[as alias]",{"type":28,"value":357},"表示为当前的异常指定一个别名，通过该别名，可以记录异常的具体内容",{"type":18,"tag":328,"props":359,"children":360},{},[361,367],{"type":18,"tag":218,"props":362,"children":364},{"className":363},[],[365],{"type":28,"value":366},"block2",{"type":28,"value":368},"：表示进行异常处理的代码块",{"type":18,"tag":370,"props":371,"children":372},"blockquote",{},[373],{"type":18,"tag":30,"props":374,"children":375},{},[376,378,383,385,391],{"type":28,"value":377},"在捕捉异常时，如果需要同时处理多个异常，可以在",{"type":18,"tag":218,"props":379,"children":381},{"className":380},[],[382],{"type":28,"value":251},{"type":28,"value":384},"语句后面使用",{"type":18,"tag":218,"props":386,"children":388},{"className":387},[],[389],{"type":28,"value":390},"()",{"type":28,"value":392},"将可能出现的异常括起来，间隔使用逗号分割。",{"type":18,"tag":213,"props":394,"children":396},{"id":395},"tryexceptelse-语句",[397,403],{"type":18,"tag":218,"props":398,"children":400},{"className":399},[],[401],{"type":28,"value":402},"try...except...else",{"type":28,"value":225},{"type":18,"tag":30,"props":405,"children":406},{},[407,409,414,416,422,424,429,431,436,438,443],{"type":28,"value":408},"还有一种方式是在",{"type":18,"tag":218,"props":410,"children":412},{"className":411},[],[413],{"type":28,"value":223},{"type":28,"value":415},"的基础上加上",{"type":18,"tag":218,"props":417,"children":419},{"className":418},[],[420],{"type":28,"value":421},"else",{"type":28,"value":423},"子句，用于指定当",{"type":18,"tag":218,"props":425,"children":427},{"className":426},[],[428],{"type":28,"value":243},{"type":28,"value":430},"语句没有发现异常时要执行的语句。当在",{"type":18,"tag":218,"props":432,"children":434},{"className":433},[],[435],{"type":28,"value":243},{"type":28,"value":437},"语句执行过程中未发现异常，则执行",{"type":18,"tag":218,"props":439,"children":441},{"className":440},[],[442],{"type":28,"value":421},{"type":28,"value":444},"子句，否则将不执行。",{"type":18,"tag":213,"props":446,"children":448},{"id":447},"tryexceptfinally-语句",[449,455],{"type":18,"tag":218,"props":450,"children":452},{"className":451},[],[453],{"type":28,"value":454},"try...except...finally",{"type":28,"value":225},{"type":18,"tag":30,"props":457,"children":458},{},[459,461,467,469,474],{"type":28,"value":460},"完整的异常处理语句应该包含",{"type":18,"tag":218,"props":462,"children":464},{"className":463},[],[465],{"type":28,"value":466},"finally",{"type":28,"value":468},"代码块，通过情况下，无论程序执行是否出现异常，而",{"type":18,"tag":218,"props":470,"children":472},{"className":471},[],[473],{"type":28,"value":466},{"type":28,"value":475},"语句都将会执行。其语法格式如下：",{"type":18,"tag":276,"props":477,"children":479},{"className":278,"code":478,"language":280,"meta":7,"style":7},"try:\n    block1\nexcept [ExceptionName [as alias]]:\n    block2\nfinally:\n    block3\n",[480],{"type":18,"tag":218,"props":481,"children":482},{"__ignoreMap":7},[483,490,497,504,511,520],{"type":18,"tag":286,"props":484,"children":485},{"class":288,"line":289},[486],{"type":18,"tag":286,"props":487,"children":488},{},[489],{"type":28,"value":295},{"type":18,"tag":286,"props":491,"children":492},{"class":288,"line":298},[493],{"type":18,"tag":286,"props":494,"children":495},{},[496],{"type":28,"value":304},{"type":18,"tag":286,"props":498,"children":499},{"class":288,"line":307},[500],{"type":18,"tag":286,"props":501,"children":502},{},[503],{"type":28,"value":313},{"type":18,"tag":286,"props":505,"children":506},{"class":288,"line":316},[507],{"type":18,"tag":286,"props":508,"children":509},{},[510],{"type":28,"value":322},{"type":18,"tag":286,"props":512,"children":514},{"class":288,"line":513},5,[515],{"type":18,"tag":286,"props":516,"children":517},{},[518],{"type":28,"value":519},"finally:\n",{"type":18,"tag":286,"props":521,"children":523},{"class":288,"line":522},6,[524],{"type":18,"tag":286,"props":525,"children":526},{},[527],{"type":28,"value":528},"    block3\n",{"type":18,"tag":213,"props":530,"children":532},{"id":531},"使用-raise-语句抛出异常",[533,535,541],{"type":28,"value":534},"使用 ",{"type":18,"tag":218,"props":536,"children":538},{"className":537},[],[539],{"type":28,"value":540},"raise",{"type":28,"value":542}," 语句抛出异常",{"type":18,"tag":30,"props":544,"children":545},{},[546,548,553],{"type":28,"value":547},"如果某个函数或者方法可能会产生异常，但不想在当前函数或者方法中处理这个异常，则可以使用 ",{"type":18,"tag":218,"props":549,"children":551},{"className":550},[],[552],{"type":28,"value":540},{"type":28,"value":554}," 语句在函数或者方法中抛出异常，其语法格式如下：",{"type":18,"tag":276,"props":556,"children":558},{"className":278,"code":557,"language":280,"meta":7,"style":7},"raise [ExceptionName[(reason)]]\n",[559],{"type":18,"tag":218,"props":560,"children":561},{"__ignoreMap":7},[562],{"type":18,"tag":286,"props":563,"children":564},{"class":288,"line":289},[565],{"type":18,"tag":286,"props":566,"children":567},{},[568],{"type":28,"value":557},{"type":18,"tag":324,"props":570,"children":571},{},[572,583],{"type":18,"tag":328,"props":573,"children":574},{},[575,581],{"type":18,"tag":218,"props":576,"children":578},{"className":577},[],[579],{"type":28,"value":580},"ExceptionName [(reason)]",{"type":28,"value":582},"：可选参数，用于指定抛出的异常名称，以及异常信息的相关描述。若省略，就会把当前的错误原样抛出。",{"type":18,"tag":328,"props":584,"children":585},{},[586,592,594,599],{"type":18,"tag":218,"props":587,"children":589},{"className":588},[],[590],{"type":28,"value":591},"reason",{"type":28,"value":593},"：参数",{"type":18,"tag":218,"props":595,"children":597},{"className":596},[],[598],{"type":28,"value":591},{"type":28,"value":600},"可以省略，若省略，则在抛出异常时，不附带任何描述信息。",{"type":18,"tag":23,"props":602,"children":604},{"id":603},"程序调试",[605],{"type":28,"value":603},{"type":18,"tag":213,"props":607,"children":609},{"id":608},"使用-idle-进行程序调试",[610],{"type":28,"value":611},"使用 IDLE 进行程序调试",{"type":18,"tag":30,"props":613,"children":614},{},[615,617,623],{"type":28,"value":616},"1.首先打开IDLE Shell窗口，在主菜单选择 Debug -> Debugger 菜单项，将打开Debug Control 对话框，同时IDLE Shell 窗口将显示",{"type":18,"tag":218,"props":618,"children":620},{"className":619},[],[621],{"type":28,"value":622},"[DEBUG ON]",{"type":28,"value":624},"表示已处于调试状态。如下图：",{"type":18,"tag":30,"props":626,"children":627},{},[628],{"type":18,"tag":629,"props":630,"children":633},"img",{"alt":631,"src":632},"Pasted image 20250715160639","\u002Fimages\u002Fblog\u002Fpython-basics\u002FPasted%20image%2020250715160639.png",[],{"type":18,"tag":30,"props":635,"children":636},{},[637,639,645,647,652],{"type":28,"value":638},"2.然后在IDLE Shell窗口中选择 File -> Open 菜单项，打开需要调试的文件，然后在想要添加断点的行上右击选择 ",{"type":18,"tag":218,"props":640,"children":642},{"className":641},[],[643],{"type":28,"value":644},"Set Breakpoint",{"type":28,"value":646},"菜单项可以添加断点，在想要取消断点的行上右击选择 ",{"type":18,"tag":218,"props":648,"children":650},{"className":649},[],[651],{"type":28,"value":644},{"type":28,"value":653},"菜单项可以取消断点。添加断点的行将以黄色底纹标记，如下图：",{"type":18,"tag":30,"props":655,"children":656},{},[657],{"type":18,"tag":629,"props":658,"children":661},{"alt":659,"src":660},"Pasted image 20250715164414","\u002Fimages\u002Fblog\u002Fpython-basics\u002FPasted%20image%2020250715164414.png",[],{"type":18,"tag":30,"props":663,"children":664},{},[665,667,673,675,681],{"type":28,"value":666},"3.在添加所需的断点（添加断点的原则是：程序执行到这个位置时，想要查看某些变量的值，就在这个位置添加一个断点）后，按",{"type":18,"tag":218,"props":668,"children":670},{"className":669},[],[671],{"type":28,"value":672},"F5",{"type":28,"value":674},"键，执行程序，这是Debug Control对话框中显示程序的执行信息，选择",{"type":18,"tag":218,"props":676,"children":678},{"className":677},[],[679],{"type":28,"value":680},"Globals",{"type":28,"value":682},"复选框，将显示全局变量，默认只显示局部变量。如下图：",{"type":18,"tag":30,"props":684,"children":685},{},[686],{"type":18,"tag":629,"props":687,"children":690},{"alt":688,"src":689},"Pasted image 20250715165146","\u002Fimages\u002Fblog\u002Fpython-basics\u002FPasted%20image%2020250715165146.png",[],{"type":18,"tag":30,"props":692,"children":693},{},[694,696,702],{"type":28,"value":695},"4.图中可以看到调试工具栏处的提供的5个按钮。此处单击",{"type":18,"tag":218,"props":697,"children":699},{"className":698},[],[700],{"type":28,"value":701},"Go",{"type":28,"value":703},"按钮继续执行程序，直到执行到所设置的第一个断点处，程序才被暂停执行，在此期间，Debug Control窗口的数据将发生变化，如下图：",{"type":18,"tag":30,"props":705,"children":706},{},[707],{"type":18,"tag":629,"props":708,"children":711},{"alt":709,"src":710},"Pasted image 20250715170121","\u002Fimages\u002Fblog\u002Fpython-basics\u002FPasted%20image%2020250715170121.png",[],{"type":18,"tag":30,"props":713,"children":714},{},[715,717,722],{"type":28,"value":716},"5.继续点击",{"type":18,"tag":218,"props":718,"children":720},{"className":719},[],[721],{"type":28,"value":701},{"type":28,"value":723},"按钮，将执行到下一个断点，查看变量的变化，直到全部断点全部执行完毕。调试工具栏的按钮状态将变为不可用，如图：",{"type":18,"tag":30,"props":725,"children":726},{},[727],{"type":18,"tag":629,"props":728,"children":731},{"alt":729,"src":730},"Pasted image 20250715170616","\u002Fimages\u002Fblog\u002Fpython-basics\u002FPasted%20image%2020250715170616.png",[],{"type":18,"tag":30,"props":733,"children":734},{},[735,737,743],{"type":28,"value":736},"6.程序调试完成后，可以关闭Debug Control对话框，此时Python Shell中将显示",{"type":18,"tag":218,"props":738,"children":740},{"className":739},[],[741],{"type":28,"value":742},"[DEBUG OFF]",{"type":28,"value":744},"表示已经结束调试。",{"type":18,"tag":30,"props":746,"children":747},{},[748],{"type":28,"value":749},"调试工具栏的5个按钮介绍：",{"type":18,"tag":36,"props":751,"children":752},{},[753,769],{"type":18,"tag":40,"props":754,"children":755},{},[756],{"type":18,"tag":44,"props":757,"children":758},{},[759,764],{"type":18,"tag":48,"props":760,"children":761},{"align":50},[762],{"type":28,"value":763},"按钮名称",{"type":18,"tag":48,"props":765,"children":766},{"align":50},[767],{"type":28,"value":768},"功能",{"type":18,"tag":60,"props":770,"children":771},{},[772,784,797,810,823],{"type":18,"tag":44,"props":773,"children":774},{},[775,779],{"type":18,"tag":67,"props":776,"children":777},{"align":50},[778],{"type":28,"value":701},{"type":18,"tag":67,"props":780,"children":781},{"align":50},[782],{"type":28,"value":783},"执行跳至断点操作",{"type":18,"tag":44,"props":785,"children":786},{},[787,792],{"type":18,"tag":67,"props":788,"children":789},{"align":50},[790],{"type":28,"value":791},"Step",{"type":18,"tag":67,"props":793,"children":794},{"align":50},[795],{"type":28,"value":796},"进入要执行的函数",{"type":18,"tag":44,"props":798,"children":799},{},[800,805],{"type":18,"tag":67,"props":801,"children":802},{"align":50},[803],{"type":28,"value":804},"Over",{"type":18,"tag":67,"props":806,"children":807},{"align":50},[808],{"type":28,"value":809},"用于单步执行",{"type":18,"tag":44,"props":811,"children":812},{},[813,818],{"type":18,"tag":67,"props":814,"children":815},{"align":50},[816],{"type":28,"value":817},"Out",{"type":18,"tag":67,"props":819,"children":820},{"align":50},[821],{"type":28,"value":822},"跳出所在的函数",{"type":18,"tag":44,"props":824,"children":825},{},[826,831],{"type":18,"tag":67,"props":827,"children":828},{"align":50},[829],{"type":28,"value":830},"Quit",{"type":18,"tag":67,"props":832,"children":833},{"align":50},[834],{"type":28,"value":835},"结束调试",{"type":18,"tag":370,"props":837,"children":838},{},[839],{"type":18,"tag":30,"props":840,"children":841},{},[842,844,849,851,856,858,863,865,870],{"type":28,"value":843},"在调试过程中，如果所设置的断点处有其他函数调用，还可以单击",{"type":18,"tag":218,"props":845,"children":847},{"className":846},[],[848],{"type":28,"value":791},{"type":28,"value":850}," 按钮进入函数内部.当确定该函数没有问题时，可以单击 ",{"type":18,"tag":218,"props":852,"children":854},{"className":853},[],[855],{"type":28,"value":817},{"type":28,"value":857},"按钮跳出该函数；或者在调试的过程中，当需要对已经发现的问题的原因进行修改时，可以直接单击 ",{"type":18,"tag":218,"props":859,"children":861},{"className":860},[],[862],{"type":28,"value":830},{"type":28,"value":864}," 按钮结束调试。另外，如果调试的目的不是很明确（即不确认问题的位置），也可以直接单击 ",{"type":18,"tag":218,"props":866,"children":868},{"className":867},[],[869],{"type":28,"value":791},{"type":28,"value":871}," 按钮进行单步执行，这样可以清晰地观察程序的执行过程和数据的变量，方便找出问题。",{"type":18,"tag":213,"props":873,"children":875},{"id":874},"使用-assert-语句调试程序",[876,877,883],{"type":28,"value":534},{"type":18,"tag":218,"props":878,"children":880},{"className":879},[],[881],{"type":28,"value":882},"assert",{"type":28,"value":884}," 语句调试程序",{"type":18,"tag":30,"props":886,"children":887},{},[888,890,896,898,903],{"type":28,"value":889},"还可以在代码中通过",{"type":18,"tag":218,"props":891,"children":893},{"className":892},[],[894],{"type":28,"value":895},"print()",{"type":28,"value":897},"函数把可能出现的变量输出，便于查看，但是会产生很多冗余信息，所以比较麻烦。因此，Python还提供了一种方法，即使用",{"type":18,"tag":218,"props":899,"children":901},{"className":900},[],[902],{"type":28,"value":882},{"type":28,"value":904},"语句进行调试。它一般被用于对程序某个时刻必须满足的条件进行验证。其语法格式如下：",{"type":18,"tag":276,"props":906,"children":908},{"className":278,"code":907,"language":280,"meta":7,"style":7},"assert expression[,reason]\n",[909],{"type":18,"tag":218,"props":910,"children":911},{"__ignoreMap":7},[912],{"type":18,"tag":286,"props":913,"children":914},{"class":288,"line":289},[915],{"type":18,"tag":286,"props":916,"children":917},{},[918],{"type":28,"value":907},{"type":18,"tag":324,"props":920,"children":921},{},[922,941],{"type":18,"tag":328,"props":923,"children":924},{},[925,931,933,939],{"type":18,"tag":218,"props":926,"children":928},{"className":927},[],[929],{"type":28,"value":930},"expression",{"type":28,"value":932},"：条件表达式。如果表达式为真，则什么都不做，否则，将抛出",{"type":18,"tag":218,"props":934,"children":936},{"className":935},[],[937],{"type":28,"value":938},"AssertionError",{"type":28,"value":940},"异常。",{"type":18,"tag":328,"props":942,"children":943},{},[944,949],{"type":18,"tag":218,"props":945,"children":947},{"className":946},[],[948],{"type":28,"value":591},{"type":28,"value":950},"：可选参数，用于对判断条件进行描述，为了以后更好的直到哪儿出现了问题。",{"type":18,"tag":952,"props":953,"children":954},"style",{},[955],{"type":28,"value":956},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":7,"searchDepth":298,"depth":298,"links":958},[959,960,961],{"id":25,"depth":307,"text":25},{"id":209,"depth":307,"text":209},{"id":603,"depth":307,"text":603},"markdown","content:blog:2025-07-10-python-异常处理及程序调试.md","content","blog\u002F2025-07-10-python-异常处理及程序调试.md","blog\u002F2025-07-10-python-异常处理及程序调试","md",1780801018419]