c# throw new exception
static void CopyObject(SampleClass original)
{
if (original == null)
{
throw new System.ArgumentException("Parameter cannot be null", "original");
}
}
c# throw new exception
static void CopyObject(SampleClass original)
{
if (original == null)
{
throw new System.ArgumentException("Parameter cannot be null", "original");
}
}
c# throw exception
try
{
//code
} catch (Exception ex){
throw new Exception(ex.Message);
}
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();
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.");
}
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us