Opengist

Explore

  • All gists
  • Topics
  • Users
Give feedback on the new UI Powered by Opengist ⋅ 56ms

user:thomas gists created by user

title:mygist gists with given title

description:sync gists with given description

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

all:systemctl search all fields

Login
s

system-calls

Recently created Least recently created Recently updated Least recently updated

timmy / 使用 errno 處理標準錯誤代碼

Last active 6 hours ago errno error-handling file-io python system-calls

errno 提供標準錯誤代碼,適用於 檔案操作、系統調用、例外處理,可提高錯誤訊息的可讀性,並方便比對特定錯誤類型。

0 0 0 3
1 import errno
2 import os
3
4 try:
5 os.remove("non_existent_file.txt") # 嘗試刪除不存在的檔案
6 except OSError as e:
7 if e.errno == errno.ENOENT:
8 print("錯誤:檔案不存在")
9 elif e.errno == errno.EACCES:
10 print("錯誤:權限不足")