초기 커밋.
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,64 @@
|
||||
class MyException : Exception
|
||||
{
|
||||
public string MyMessage = string.Empty;
|
||||
public MyException(string message, Exception ex) :base(ex.Message)
|
||||
{
|
||||
MyMessage = message;
|
||||
}
|
||||
}
|
||||
|
||||
internal class Program
|
||||
{
|
||||
static void Step1()
|
||||
{
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
static void Step2()
|
||||
{
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
static void Step3()
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
static bool Log(Exception ex)
|
||||
{
|
||||
Console.WriteLine($"{DateTime.Now.ToString("yy/MM/dd HH:mm:ss")} - {ex.Message}");
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 실행 문장들
|
||||
Step1();
|
||||
Step2();
|
||||
Step3();
|
||||
}
|
||||
catch (IndexOutOfRangeException ex)
|
||||
{
|
||||
// 새로운 Exception 생성하여 throw
|
||||
throw new MyException("Invalid index", ex);
|
||||
}
|
||||
catch (FileNotFoundException ex)
|
||||
{
|
||||
bool success = Log(ex);
|
||||
if (!success)
|
||||
{
|
||||
// 기존 Exception을 throw
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log(ex);
|
||||
// 발생된 Exception을 그대로 호출자에 전달
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
//TODO 사용한 메모리 정리 코드
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user