2016-06-19 6 views
0

特別なエラー処理/ログシステムを組み込んだ独自の例外を実装するのは悪い考えですか?私はエラー処理のものを一箇所に集中させたいと思っています。例えばPython:エラー処理ルーチンが組み込まれたカスタム例外?

:明らか

errors.py

class ReallyBadException(Exception): 
    def __init__(self, msg, error_handling): 
     super(Exception, self).__init__(msg) 
     ... 
     error_handling.logger.error(msg) 
     error_handling.db.do_stuff(msg) 
     call_the_police() 
     ... 

私はまだメイン関数などで局所的に例外を処理する必要があります

main.py

を知っています
from errors import ReallyBadException, NotSoBadException, ... 
... 
try: 
    do_something() 
except RellyBadException: 
    do_another_thing() 

答えて

0

簡単に言えば、これはまったく悪い考えではありません。

実際、私が見ているように、あなたがしようとしているのは、プログラミング言語が例外処理を最初に持っている理由です。

関連する問題