'''class a():
pass
try:
print(a.x)
except attributeerror as x:
print(x)'''
'''a=
try:
print(a["age"])
except keyerror as a:
print(a)'''
'''a=[1,2,3,4,5]
b=iter(a)
try:
while true:
print(next(b))
except stopiteration as n:
print(n)'''
'''a=[1,2,3]
try:
print(a[5])
print(1/0)
print("33333333333")
# except (zerodivisionerror,indexerror) as z:
# print(z)
except:
print("我有錯")
else:
print("我沒錯")'''
'''try:
f=open("cuowu.txt","r")
f.write("1234")
except:
print("錯誤")
finally:
print('i love you')
f.close'''
'''with open("cuowu.txt","r",encoding="utf-8") as f:
x=f.read()
print(x)
raise indexerror("錯了") #丟擲異常'''
'''a=[1,2,3,4,5]
try:
print(a[7])
print("北京歡迎您")
except indexerror as i:
print(i)'''
'''class myerror(exception):
def __init__(self,gms):
self.gms=gms
def __str__(self):
return str(self.gms+"就是閒的")
try:
raise myerror("我其實沒錯,")
except myerror as m:
print(m)'''
'''class student():
def __init__(self,name,age,score):
self.name=name
self.age=age
self.score=score
zs=student("張三",18,98)
print(dir(zs))
print(zs.name)'''
'''class people():
adress="朝陽區"
def __init__(self,name):
self.name=name
xh=people("小紅")
print(xh.name,xh.adress)
xm=people("小明")
print(xm.name,xm.adress)
xm.adress="東勝"
print(xm.name,xm.adress)
delattr(xm,"adress")
print(xm.adress)'''
'''class a():
def aa(self):
print(self.name)
class b(a):
def __init__(self,name):
self.name=name
b=b("小明")
b.aa()'''
'''class a():
def __init__(self,name):
self.name=name
def haha():
print("你好")
a=a("李峰")
a.haha=haha #方法傳入只能是靜態方法
a.haha()'''
'''class a():
money=100000
def __init__(self,name):
self.name=name
@classmethod
def clsm(cls):
print(cls.money)
a=a("小明")
a.clsm()'''
#單例模式
'''class a():
def __new__(cls, *args, **kwargs):
if not hasattr(a,"bowen"):
cls.bowen=object.__new__(cls)
return cls.bowen
def __init__(self,name):
self.name=name
a=a("呵呵")
b=a("哈哈")
c=a("嘿嘿")
print(b is c)
print(a==c)
print(a.name)
print(b.name)'''
import os
a=input("請輸入多級目錄名:")
b=a.split("\\")
print(b)
p=os.getcwd()
for dg in b:
# p=p+"\\"+dg
p=os.path.join(p,dg)
if not os.path.exists(p):
os.mkdir(p)
print(p)
struts 異常處理 全域性異常處理
記錄一下全域性異常處理的過程 處理主動丟擲的異常,轉向錯誤提示頁面。1 寫乙個自己的異常,繼承runtimeexception,從父類生成構造方法 package me.yndy.srtp.exception suppresswarnings serial public class errorexc...
python異常處理 Python 異常處理
使用者輸入不完整 比如輸入為空 或者輸入非法 輸入不是數字 異常就是程式執行時發生錯誤的訊號,在python中,錯誤觸發的異常如下 在python中不同的異常可以用不同的型別 python中統一了類與型別,型別即類 去標識,不同的類物件標識不同的異常,乙個異常標識一種錯 觸發indexerror 觸...
01 異常 異常處理
注意 1 對定義的變數能初始化的盡量初始化,如果賦的值可能產生誤導,可以採用可空型別 例如 double?dnumres null 3 異常 執行的時候出現的錯誤,或bug 編寫 的預期條件玉實際條件不穩合 異常的機制是為了保證程式可以一直正常執行。丟擲異常 throw new exception ...