e9cbf23ab5
이전 재구성 작업에서 Dev/ 폴더가 누락되었던 것을 반영. - Dev/Topic_Programming(중첩 폴더, 78개)은 Dev 자체 최상위 폴더들 (Architecture/Conventions/Engineering_Intelligence 등)과 완전 중복이라 제거. - Dev 최상위 엔지니어링 지식 폴더(Architecture/Conventions/Engineering_Intelligence/ Failure_Library/Generalized_Principles/Language/Pattern_Catalog/Platform_Guides/ Subsystems, 77개)는 이미 Topic_Programming/Topic_Programming에 더 최신 버전이 존재해 중복 제거(고유 콘텐츠 1개는 예외 처리하여 이동 보존). - Dev의 W3Schools 언어 튜토리얼 폴더(Topic_C/CPP/CSS/CSharp/HOWTO/HTML/Java/ JavaScript/PHP/Python/SQL/W3CSS, 1201개)는 전부 Topic_Programming 하위로 이동. - 에이전트 운영 상태(.astra/docs)는 그대로 유지, 콘텐츠 폴더만 정리. - Topic_Programming 최종 문서 수: 2784 → 3985.
4.0 KiB
4.0 KiB
id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
| id | title | category | status | verification_status | canonical_id | aliases | duplicate_of | source_trust_level | confidence_score | created_at | updated_at | review_reason | merge_history | tags | raw_sources | applied_in | github_commit | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| python-try-except | Python Try Except | Programming_Language | draft | conceptual |
|
B | 0.9 | 2026-07-04 | 2026-07-04 |
|
|
Python Try Except
🎯 한 줄 통찰 (One-line insight)
try/except/else/finally each answer a distinct question — try (what might fail), except (what to do on failure), else (what to do on success), finally (what must ALWAYS run) — and finally is what guarantees cleanup like closing a file even when an error occurs. [S1]
🧠 핵심 개념 (Core concepts)
try— tests a block of code for errors. [S1]except— handles the error if the try block raises one. [S1]else— runs only if the try block raised NO error. [S1]finally— runs regardless of whether an error occurred. [S1]- Multiple except blocks — catch different error types differently (e.g.
except NameError:vs. bareexcept:). [S1] raise— explicitly throws an exception, optionally with a specific type (TypeError, customException) and message. [S1]
🧩 추출된 패턴 (Extracted patterns)
- finally for resource cleanup — the canonical example opens a file inside try, writes inside a nested try/except, and uses
finally: f.close()to guarantee the file handle closes even if the write fails — the program never leaves a file open. [S1]
📖 세부 내용 (Details)
- Basic exception handling:
try: print(x) except: print("An exception occurred"). [S1] - Multiple except types:
try: print(x) except NameError: print("Variable x is not defined") except: print("Something else went wrong"). [S1] - else on success:
try: print("Hello") except: ... else: print("Nothing went wrong"). [S1] - finally for cleanup: [S1]
try:
f = open("demofile.txt")
try:
f.write("Lorum Ipsum")
except:
print("Something went wrong when writing to the file")
finally:
f.close()
except:
print("Something went wrong when opening the file")
- Raising a custom exception:
x = -1; if x < 0: raise Exception("Sorry, no numbers below zero"). [S1] - Raising a typed exception:
if not type(x) is int: raise TypeError("Only integers are allowed"). [S1]
⚖️ 모순 및 업데이트 (Contradictions & updates)
소스에서 모순되는 정보는 발견되지 않음.
🛠️ 적용 사례 (Applied in summary)
현재 발견된 실제 적용 사례가 없습니다 — Python User Input 챕터에서 이 예외 처리가 사용자 입력 검증 루프에 직접 적용된다. [S1]
💻 코드 패턴 (Code patterns)
finally guarantees cleanup (Python):
try:
f = open("demofile.txt")
try:
f.write("Lorum Ipsum")
except:
print("Something went wrong when writing to the file")
finally:
f.close()
except:
print("Something went wrong when opening the file")
✅ 검증 상태 및 신뢰도
- 상태: draft
- 검증 단계: conceptual
- 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
- 신뢰 점수: 0.90
- 중복 검사 결과: 신규 생성 (New discovery)
🔗 지식 그래프 (Knowledge Graph)
- 상위/루트: Python Tutorial
- 관련 개념: Python User Input, Python File Handling
- 참조 맥락: 오류 처리의 표준 패턴 — 사용자 입력 검증, 파일 자원 정리에 직접 적용된다.
📚 출처 (Sources)
- [S1] W3Schools — Python Try Except — https://www.w3schools.com/python/python_try_except.asp
📝 변경 이력 (Change history)
- 2026-07-04: Initial draft synthesized from the W3Schools "Python Try Except" page (Astra wiki-curation, P-Reinforce v3.1 format).