Rewrite method DivInt() using a specific exception handler to deal with the problem identified in question 1. A Console.WriteLine statement must be used to give meaningful feedback to the user/client that something went wrong.

Mohapi Wendy 0 Reputation points
2023-03-24T12:05:56.5066667+00:00

static int DivInt(int A, int B)

{

return A / B:

}

private static void ExceptionH()

{

Console.WriteLine(DivInt(10,2))

};

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,839 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sedat SALMAN 13,740 Reputation points
    2023-03-25T20:18:35.46+00:00

    you mean??????????

    static int DivInt(int A, int B)
    {
    if(B == 0)
    {
    throw new ArgumentException("Cannot divide by zero");
    }
    return A / B;
    }
    private static void ExceptionH()
    {
    try
    {
    Console.WriteLine(DivInt(10, 0));
    }
    catch (ArgumentException ex)
    {
    Console.WriteLine("Error: " + ex.Message);
    }
    }
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.