본문 바로가기

예외처리5

[C#][Study][기초다지기] 예외처리 예외처리 - try : 예외를 일으킬 수 있는 코드 식별 - catch : 예외처리 - throw : 사용자 정의 예외 메시지 생성 - finally : 예외 발생 여부에 관계없이 실행 [ex] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Exception_Handling { class Program { static void Main(string[] args) { label: // Try block: 런타임에 발생하는 예외를 확인한다. try { int num1, num2; decimal result; Console.Write.. 2023. 9. 23.
[C#][Study][기초다지기] uncheck 문 uncheck 문 - 스택 오버플로우가 발생해도 예외를 무시하고 실행시킴 - 잘못된 출력이 발생할 가능성이 높음 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Unchecked_Statement { class Program { static void Main(string[] args) { int num = int.MaxValue; // int의 최대값 할당 try { unchecked { // 스택 오버플로우 발생 -> 예외를 처리하지 않고 잘못된 값을 출력함 num = num + 1; Console.WriteLine(num); } } catch (Exception e) { Cons.. 2023. 9. 23.
[C#][Study][기초다지기] check 문 check 문 - 오버플로우나 언더플로우시 예외를 발생시킴 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Checked_Statement { class Program { static void Main(string[] args) { int num = int.MaxValue; // int의 최대값 할당 try { checked { // int의 최대값을 넘게하여 스택 오버플로우를 강제로 발생시킴 num = num + 1; Console.WriteLine(num); } } catch (Exception e) { Console.WriteLine(e.ToString()); } Console.. 2023. 9. 23.
[C#][Study][기초다지기] throw 문 throw 문 - 예외를 처리할 때 사용 - 예외는 catch 블록에서 처리됨 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace throw_statement { class Program { static void Main(string[] args) { int num1, num2, result; Console.WriteLine("Enter First Number"); num1 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Second Number"); num2 = Convert.ToInt32(Console.ReadLine.. 2023. 9. 23.
[WPF][C#][Study] WPF 시작 2일차 1. XAML 이벤트 - 마우스 이벤트 - MouseUp : 마우스를 놓을 때 발생 - MouseDown : 마우스를 누를 때 발생 - 이벤트를 생성하는 2가지 방법 1) XAML에서 직접 호출 // 1) 위처럼 MouseUp의 델리게이트를 직접 연결해줌 2) Code-behind에서 델리게이트 추가 using System; using System.Windows; using System.Windows.Input; namespace WpfTutorialSamples.XAML { public partial class EventsSample : Window { public EventsSample() { InitializeComponent(); // 2) Code-behind에서 델리게이트에 직접 추가함 pnl.. 2023. 9. 15.