Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- AI
- amazon q
- VPC
- list
- git
- nosql
- debug_toolbar
- Amazon
- django
- MongoDB
- ai assistant
- tgw
- pyspark
- SCALA APP
- Transit Gateway
- Spark
- debug toolbar
- mcponaws
- django-debug-toolbar
- 툴바안뜸
- Eclipse
- json
- Python
- devops
- AWS
- AWSKRUG
- ubuntu
- coding with ai
Archives
- Today
- Total
STACKBASE
[Python] raise 구문 본문
반응형
1. 에러를 강제로 발생시킬 때 사용
2. 형태
raise 예외("에러 메세지")
3. 에러 만들기
class 예외(Exception):
def __init__(self):
super().__init__("에러 메세지")
4. 예제
class PositiveError(Exception):
def __init__(self):
super().__init__("양수 입력 불가!")
try:
val = int(input('input negative number: '))
if val >= 0:
raise PositiveError
except PositiveError as e:
print("에러 발생", e)
반응형
'프로그래밍 > Python' 카테고리의 다른 글
[Python] map, filter 함수 (0) | 2021.11.28 |
---|---|
[Python] lambda function (0) | 2021.11.28 |
[Python] 위치/키워드 가변 매개변수 (0) | 2021.11.28 |
[Python] 리스트 할당과 복사 (0) | 2021.11.24 |
[Python] try, except 구문 (0) | 2021.11.21 |