728x90 반응형 SMALL python finally1 Python - 예외 처리 예외처리는 try ~ except 문을 통해 처리 한다. 기본 문법은 아래와 같다. try: # do something except EOFError: print('why did you do an eof on me?') else: print('No exception') 다른 언어에서 처럼 예외클래스를 custom 하게 만들 수도 있다. 마찬가지로 finally 를 이용하면 예외가 발생하더라도 안전하게 후처리를 할 수 있다. class ShortInputException(Exception): '''A user-defined exception class''' def __init__(self, length, atleast): Exception.__init__(self) self.length = length se.. 2018. 9. 18. 이전 1 다음 728x90 반응형 LIST