using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a, b;
try
{
checked
{
a = int.MaxValue;
b = a + 1;
Console.WriteLine(b);
}
}
catch (OverflowException oe)
{
Console.WriteLine(oe.Message);
}
}
}
}
*결과
-> 산술계산의 결과 오버플로가 발생했습니다.
* checked 문과 unchecked문은 사용법이 같음
* unchecked 문은 예외 처리를 하지 않고 오버플로를 무시하고 결과를 반환하는 것이므로
catch (OverflowException oe)
{
Console.WriteLine(oe.Message);
의 예외 처리는 필요하지 않음






최근 덧글