인수의 형식이 유효하지 않은 경우 FomatException이 발생합니다.
예를 들어 보겠습니다.
int 이외의 값을 int.Parse() 메서드에 설정하면 아래와 같이 FormatException이 발생합니다. -
예시
using System;
class Demo {
static void Main() {
string str = "3.5";
int res = int.Parse(str);
}
} 정수 이외의 값을 전달했기 때문에 위의 프로그램을 컴파일할 때 다음 오류가 발생합니다.
출력
Unhandled Exception: System.FormatException: Input string was not in a correct format.