낑깡의 게임 프로그래밍 도전기

C# try catch 본문

C#

C# try catch

낑깡겜플밍 2025. 7. 14. 12:55
반응형

에러가 무조건 발생하는 곳에서 많이 쓴다.
ex) 네트워크처리, 파일 불러오기

서버에러코드 103을 던지기도하는데 Exception를 던지는게 트렌드다

static GiftBox giftBox;

try
{
	Console.WriteLine("레터 출력");
    Console.WriteLine(giftBox.Letter);
}
catch (NullReferenceException e) //해당 조건이면 여기서 캐치
{
	Console.WriteLine("NullReferenceException e:");
    Console.WriteLine(e);
}
finally
{
	Console.WriteLine("무조건 실행");
}
Console.WriteLine("종료");

 

 

 

반응형

'C#' 카테고리의 다른 글

C# 디버깅  (0) 2025.07.17
C# 프로퍼티(Property)  (0) 2025.07.15
C# null 처리  (0) 2025.07.13
C# 흐름제어(if, switch, 삼항연산자, while, do while, break, countinue, 2중 for문)  (2) 2025.07.11
C# 연산자  (3) 2025.07.08