Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
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
Archives
Today
Total
관리 메뉴

For me

[Unity] 3) Exception 본문

Unity/이론

[Unity] 3) Exception

GiveZero 2023. 2. 28. 22:05

예외 Exception

예정된 프로그램 흐름에서 벗어나는 사건

 

이것을 예외처리(Exception Handling) 해주어야함

 

Try ~ Catch 문

try
{
 	//TODO
}
catch(예외객체1)
{
	// 예외 발생시 처리
}
catch(예외객체2)
{
	// 예외 발생시 처리
}
finally
{
	// 뒷정리
}

다음과 같이 진행

 

finally문은 try~catch 블록 마지막에 붙여 사용 (뒷정리)

예외가 일어나든 일어나지 않든 실행

 

사용자 정의 예외 클래스

class MyException : Exception
{
	//...
}

 

예외 필터

catch 블록이 조건을 만족하는 예외 객체만 받아들이는 장치

when 절 이용

class FilterableException : Exception
{
	public int ErrorNo {get;set;}
}

try
{
	int num = GetNumber();
    if(num < 0 || num > 10)
    	throw new FilterableException() { ErroNo = num };
    else
    	Console.WritleLine($"Output : {num}");
}
catch(FilterableException e) when (e.ErrorNo < 0)
{
	//...
}

'Unity > 이론' 카테고리의 다른 글

[Unity] 6) Addressable  (0) 2023.03.03
[Unity] 5) Nullable  (0) 2023.03.01
[Unity] 4) Reflection 과 Attribute  (0) 2023.02.28
[Unity] 2) Delegate 와 Event  (0) 2023.02.28
[Unity] 1) Invoke 와 Coroutine의 차이  (0) 2023.02.28