try:
# 例外が発生しうる処理
except Exception as e:
# 例外発生時の処理
import traceback
try:
# 例外が発生しうる処理
except Exception as e:
# 例外発生時の処理
error_message = traceback.format_exc()
try:
# 例外が発生しうる処理
except Exception as e:
# 例外発生時の処理
else:
# 正常終了時の処理
finally:
# 終了時の処理
try:
# 例外が発生しうる処理
except ZeroDivisionError as e:
# ゼロ割の例外発生時の処理
except Exception as e:
# その他の例外発生時の処理
else:
# 正常終了時の処理
finally:
# 終了時の処理
import subprocess
from subprocess import CompletedProcess
class MyCustomException(Exception):
pass
class MyClass():
def __init__():
pass
def myfunc(self):
cp: CompletedProcess = subprocess.run(
['msgconvert', input_path_str, '--outfile', f'{input_path.with_suffix(".eml")}'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
)
if cp.returncode != 0:
raise MyCustomException(f"msgconvert faild : {cp.stderr.decode()}")