Answers for "C# Throw Exception"

C#
12

c# throw new exception

static void CopyObject(SampleClass original)
{
    if (original == null)
    {
        throw new System.ArgumentException("Parameter cannot be null", "original");
    }
}
Posted by: Guest on February-26-2020
1

c# throw exception

try 
{
  //code
} catch (Exception ex){
  throw new Exception(ex.Message);
}
Posted by: Guest on September-27-2021
0

C# Throw Exception

int num1, num2, result;

            Console.WriteLine("Enter First Number");
            num1 = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Enter Second Number");
            num2 = Convert.ToInt32(Console.ReadLine());

            try
            {
                if (num2 == 0)
                {
                    throw new Exception("Can't Divide by Zero Exception\n\n");
                }
                result = num1 / num2;
                Console.WriteLine("{0} / {1} = {2}", num1, num2, result);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.ToString());
            }
            Console.ReadLine();
Posted by: Guest on June-22-2021
0

exception in asp.net c#

class Program
{
    static void Main(string[] args)
    {
        try
        {
            Console.WriteLine("Enter a number: ");

            var num = int.parse(Console.ReadLine());

            Console.WriteLine($"Squre of {num} is {num * num}");
        }
        catch(Exception ex)
        {
            Console.Write("Error info:" + ex.Message);
        }
        finally
        {
            Console.Write("Re-try with a different number.");
        }
    }
}
Posted by: Guest on October-31-2020

C# Answers by Framework

Browse Popular Code Answers by Language