코딩연습/C#
[C#]강제로 예외던지기(throw)
by 호아니
2020. 6. 12.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp11
{
class Program
{
static void Dosomething(int n)
{
if (n < 10) Console.WriteLine($"{n}");
else throw new Exception("n이 10보다 큽니다"); //강제로 예외던지기(throw)
}
static void Main(string[] args)
{
try {
Dosomething(1);
Dosomething(5);
Dosomething(10);
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}