কম্পিউটার টিউটোরিয়াল

পাইথনে এক্সসেপশন হ্যান্ডল করার পদ্ধতি

পাইথনে এক্সসেপশন হ্যান্ডল করার সবচেয়ে সহজ পদ্ধতি হলো "try-except" ব্লক ব্যবহার করা।

উদাহরণ

try:
    fob = open("test.txt", "r")
    fob.write("This is my test file for exception handling!!")
except IOError:
    print("Error: can't find the file or read data")
else:
    print("Write operation is performed successfully on the file")
    fob.close()

আউটপুট

Error: can't find the file or read data
  1. পাইথনে raise কীওয়ার্ড দিয়ে এক্সসেপশন রেইজ করা

  2. পাইথনে এক্সসেপশন হ্যান্ডল করার পদ্ধতি

  3. পাইথনে লুপের ভিতরে এক্সসেপশন হ্যান্ডল করা

  4. পাইথন লিস্ট কম্প্রিহেনশনে এক্সসেপশন কীভাবে ক্যাচ করবেন?