Files
2nd/10_Wiki/Topics/Domain_Programming/Topic_CSharp/CSharp_Exceptions.md
T
Antigravity Agent c24165b8bc refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게
[공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류.
문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인).

- Topic_Programming → Domain_Programming (내부 구조 보존)
- Topic_Graphic → Domain_Design
- Topic_Business → Domain_Product
- Topic_General → Domain_General
- _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning),
  Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing)
- 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서)
- 빈 폴더 정리 (memory/procedures)
- 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 11:05:56 +09:00

5.8 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
csharp-exceptions C# Exceptions - Try..Catch Programming_Language draft conceptual
try catch finally throw C#
e.Message
C# 예외 처리
B 0.85 2026-07-04 2026-07-04
csharp
programming-language
w3schools
exceptions
https://www.w3schools.com/cs/cs_exceptions.php

CSharp Exceptions

🎯 한 줄 통찰 (One-line insight)

The try { } catch (Exception e) { } finally { } structure is functionally identical to C++'s exception handling already documented in [[CPP Exceptions]], but where C++ typically catches by REFERENCE to a specific exception type (catch (std::exception& e)) and reads its message via .what(), C# catches the generic base Exception type and reads the message via a .Message PROPERTY (no parentheses — consistent with the property-not-method pattern already confirmed for .Length in the Strings chapter); throw new ArithmeticException("...") also demonstrates that C# ships a family of ready-made, semantically-named exception classes (ArithmeticException, FileNotFoundException, IndexOutOfRangeException, TimeOutException) rather than requiring the programmer to define custom exception types from scratch for common cases. [S1]

🧠 핵심 개념 (Core concepts)

  • Exception — the technical term for an error C# "throws" when something goes wrong (bad input, coding errors, unforeseen conditions). [S1]
  • try { } — a block of code tested for errors during execution. [S1]
  • catch (Exception e) { } — a block that runs IF an error occurs inside the paired try block; e is a variable holding the exception object. [S1]
  • e.Message — a property (no parentheses) on the caught exception, describing what went wrong. [S1]
  • finally { } — runs AFTER the try/catch, regardless of whether an error occurred or was caught. [S1]
  • throw new ExceptionType("message") — creates and raises a CUSTOM error, using one of C#'s built-in exception classes (ArithmeticException, FileNotFoundException, IndexOutOfRangeException, TimeOutException, etc.). [S1]

📖 세부 내용 (Details)

  • Unhandled error: int[] myNumbers = {1, 2, 3}; Console.WriteLine(myNumbers[10]);System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'. [S1]
  • Caught with built-in message: try { ...myNumbers[10]... } catch (Exception e) { Console.WriteLine(e.Message); }"Index was outside the bounds of the array.". [S1]
  • Caught with custom message: catch (Exception e) { Console.WriteLine("Something went wrong."); }"Something went wrong." (note: e is available but not necessarily used). [S1]
  • With finally: adding finally { Console.WriteLine("The 'try catch' is finished."); } runs that line AFTER the catch block regardless of outcome. [S1]
  • Custom throw: static void checkAge(int age) { if (age < 18) { throw new ArithmeticException("Access denied - You must be at least 18 years old."); } else { Console.WriteLine("Access granted - You are old enough!"); } } ... checkAge(15); → throws System.ArithmeticException: 'Access denied...'; checkAge(20); → prints "Access granted - You are old enough!". [S1]

⚖️ 모순 및 업데이트 (Contradictions & updates)

  • C++의 예외 처리와 구조는 동일, 메시지 접근 방식이 다름: try/catch/finally 구조 자체는 [[CPP Exceptions]]에서 확인된 C++와 차이가 없지만, C++가 보통 .what() 메서드로 예외 메시지를 얻는 반면 C#은 .Message라는 프로퍼티(괄호 없음)로 접근한다는 점이 확인됨 — Strings 챕터에서 확인된 프로퍼티 vs 메서드 구분이 예외 객체에도 그대로 적용됨. [S1]
  • 즉시 사용 가능한 다양한 내장 예외 클래스 제공: ArithmeticException, FileNotFoundException, IndexOutOfRangeException, TimeOutException 등 의미가 명확한 예외 클래스들이 기본 제공되어, throw할 때 매번 커스텀 예외 타입을 새로 정의할 필요가 없다는 점이 확인됨. [S1]

🛠️ 적용 사례 (Applied in summary)

나이가 18세 미만이면 ArithmeticException을 throw하고, 18세 이상이면 "Access granted"를 출력하는 checkAge() 함수 예제가 원문에서 직접 실전 활용 사례로 제시됨. [S1]

💻 코드 패턴 (Code patterns)

try/catch/finally with a custom throw (C#):

static void checkAge(int age)
{
    if (age < 18)
    {
        throw new ArithmeticException("Access denied - You must be at least 18 years old.");
    }
    else
    {
        Console.WriteLine("Access granted - You are old enough!");
    }
}

try
{
    checkAge(15);
}
catch (Exception e)
{
    Console.WriteLine(e.Message);  // property, no parentheses
}
finally
{
    Console.WriteLine("The 'try catch' is finished.");
}

검증 상태 및 신뢰도

  • 상태: draft
  • 검증 단계: conceptual
  • 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
  • 신뢰 점수: 0.85
  • 중복 검사 결과: 신규 생성 (New discovery)

🔗 지식 그래프 (Knowledge Graph)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-07-04: Initial draft synthesized from the W3Schools "C# Exceptions - Try..Catch" page (Astra wiki-curation, P-Reinforce v3.1 format).