• 회원가입
  • 로그인
  • 구글아이디로 로그인

[keyword] Python - try 키워드 - 코드 에러 체크. (= 트라이)

988  

try 예제

 

# (x > 3) 에러 유발. (∵x 정의 안 함.)

try:

  x > 3

except:

  print("뭔가 오류 발생.")

print("에러 떠도, 프로그램은 계속 작동.")

 

결과값:

뭔가 오류 발생.

에러 발생해도, 프로그램은 계속 작동.

 

try 정의

 

try...except...구문에서 코드 에러 유무 테스트.

※ 여러 except 구문 사용해, 에러 종류별로 각각 제어 가능.

※ finally 구문 사용해, 에러 유무와 상관없이 코드 실행 가능.

 

 

try 예제 

※ raise Exception 구문 사용해, 수동으로 에러 제어코드 실행 가능.

※ x 미정의해 일부러 에러 야기시켜 에러 제어 코드 작동 상태 점검.

 

try:

  x > 3

except:

  raise Exception("뭔가 에러 발생")

print("에러 발생 시, 프로그램 멈춤.")

 

결과값: 에러 코드 잔뜩 뜸. ㅡㅡ;;



분류 제목
module Python - math.log() 메서드 -
module Python - math.log10() 메서드 -
module Python - math.log1p() 메서드 -
module Python - math.log2() 메서드 -
module Python - math.perm() 메서드 -
module Python - math.pow() 메서드 ★ - 승수값 (= 누승값 = pow메서드 = 포오 = 파워)
module Python - math.prod() 메서드 -
module Python - math.radians() 메서드 -
module Python - math.remainder() 메서드 ★ - 나머지 반환. (= remainder메서드 = …
module Python - math.sin() 메서드 -
module Python - math.sinh() 메서드 -
module Python - math.sqrt() 메서드 -
module Python - math.tan() 메서드 -
module Python - math.tanh() 메서드 -
module Python - math.trunc() 메서드 ★ - 정수 부분 반환. (= trunc메서드 = 트렁크)
module Python - math.e 상수 - 오일러 상수 (2.71...)
module Python - math.inf 상수 - float 자료형의 무한대 상수 (= inf) 반환.
module Python - math.nan 상수 - float 자료형의 NaN 상수 (= nan) 반환.
module Python - math.pi 상수 - 원주율 (= 3.14...) 반환. (= 파이 상수)
module Python - math.tau 상수 - 원주율 2배 (= 6.28...) 반환. (= 타우 상수)
21/24
목록
찾아주셔서 감사합니다. Since 2012