728x90
SMALL

// throwで意的に例外を投げよう

using System;

 

class Lesson10

{

    public static void Main()

    {

        Console.WriteLine("Hello World");

 

        try

        {

            int number = 2;

            int answer = 100 / number;

            Console.WriteLine(answer);

            throw new DivideByZeroException();

            //2로 나누고 answer 50이 되지만, 예외처리를 발생시켜서 나오게 한다.

           

        }

        catch (DivideByZeroException e)

        {

            Console.WriteLine("0では割り算できません");

            Console.Error.WriteLine(e);

        }

        finally

        {

            Console.WriteLine("Hello C#");

        }

    }

}

 

////////////////

// throwで意的に例外を投げよう

using System;

 

class Lesson10

{

    public static void Main()

    {

        Console.WriteLine("Hello World");

 

        try

        {

            int number = 2;

            int answer = 100 / number;

            Console.WriteLine(answer);

            throw new Exception("制エラ");

            //2로 나누고 answer 50이 되지만, 예외처리를 발생시켜서 나오게 한다.

            //DivideByZeroException에서 Exception으로 바꾸면 에러 발생

           

           

        }

        catch (DivideByZeroException e)

        {

            Console.WriteLine("0では割り算できません");

            Console.Error.WriteLine(e);

        }

        catch (Exception e)

        {

            Console.WriteLine("例外が生しました");

            Console.Error.WriteLine(e);

        }

       

        finally

        {

            Console.WriteLine("Hello C#");

        }

    }

}

////////////////////////

///과제

// throwで意的に例外を投げよう

using System;

 

class Lesson10

{

    public static void Main()

    {

        Console.WriteLine("Hello World");

 

        try

        {

            int number = 2;

            int answer = 100 / number;

            Console.WriteLine(answer);

throw new DivideByZeroException();

        }

        catch (DivideByZeroException e)

        {

            Console.Error.WriteLine("0では割り算できません");

        }

        finally

        {

            Console.WriteLine("Hello C#");

        }

    }

}

728x90

설정

트랙백

댓글