-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
94 lines (86 loc) · 2.4 KB
/
Program.cs
File metadata and controls
94 lines (86 loc) · 2.4 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSException32
{
internal class Program
{
class BoxWrongWidthException : Exception
{
public BoxWrongWidthException(string message) : base(message)
{
}
}
class BoxWrongHeightException : Exception
{
public BoxWrongHeightException(string message) : base(message)
{
}
}
class Box
{
private int width;
public int Width
{
get { return width; }
set
{
if (value < 0)
throw new BoxWrongWidthException("너비는 0보다 큰 수가 되어야 합니다.");
width = value;
}
}
private int height;
public int Height
{
get { return height; }
set
{
if (value < 0)
throw new BoxWrongHeightException("높이는 0보다 큰 수가 되어야 합니다.");
height = value;
}
}
public Box(int width, int height)
{
Width = width;
Height = height;
}
public int Area
{
get { return width * height; }
}
}
static void Main(string[] args)
{
try
{
Box box = new Box(100, 100);
box.Width = 200;
box.Height = 200;
Console.WriteLine(box.Area);
Box wrongBox = new Box(10, 10);
wrongBox.Width = -10;
//wrongBox.Height = -10;
}
catch (BoxWrongWidthException e)
{
Console.WriteLine("너비 값 제대로 안넣을래?");
}
catch (BoxWrongHeightException e)
{
Console.WriteLine("높이 값 제대로 안넣을래?");
}
catch (Exception e)
{
Console.WriteLine("알 수 없는 에러?");
}
finally
{
Console.WriteLine("프로그램 종료");
}
}
}
}