Python ดักจับ Error อยากรู้คำสั้ง Exception ทุกตัว ว่าใช้งานด้านใดบ้าง

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: Python ดักจับ Error อยากรู้คำสั้ง Exception ทุกตัว ว่าใช้งานด้านใดบ้าง

Python ดักจับ Error อยากรู้คำสั้ง Exception ทุกตัว ว่าใช้งานด้านใดบ้าง

โดย nuattawoot » 14/06/2017 3:21 pm

Python ดักจับ Error อยากรู้คำสั้ง Exception ทุกตัว ว่าใช้งานด้านใดบ้าง
ตัวอย่างเช่น

try:
var_number = int(raw_input("Enter Number "))
except ValueError:
print "Please enter only numbers.."
sys.exit()


เป็นการดักการกรอกตัวอักษร ถ้าไม่ได้กรอกตัวเลขก็จะขึ้นError ,มันจะมาเข้าเงื่อนไข ของ Except ก็จะแสดงPlease enter only numbers.
แต่อยากรู้คำสั่งอื่น คับ

ข้างบน