c# how to create exception by itself
using System;
using System
.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace exceptionhandling_02{
public class book:ApplicationException{
public book(string issued)
: base(issued)
{
}
}
public class gain_info {
public string iss;
public void get_info()
{
Console.WriteLine("WELCOME TOO OXFORD LIBRARY");
Console.WriteLine("enter your book name");
iss = Console.ReadLine();
if (iss == "C#" || iss == "c#")
{
throw (new book("OOP BOOK CANT BE ISSUED"));
}
else
{
Console.WriteLine("you have issued this book :{0}", iss);
}
}
}
class program
{
static void Main(string[] args)
{
shuru:
gain_info obj = new gain_info();
try {
obj.get_info();
}
catch(book e)
{
Console.WriteLine("exception caught ",e.Message);
}
goto shuru;
}
}
}
using System
.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace exceptionhandling_02{
public class book:ApplicationException{
public book(string issued)
: base(issued)
{
}
}
public class gain_info {
public string iss;
public void get_info()
{
Console.WriteLine("WELCOME TOO OXFORD LIBRARY");
Console.WriteLine("enter your book name");
iss = Console.ReadLine();
if (iss == "C#" || iss == "c#")
{
throw (new book("OOP BOOK CANT BE ISSUED"));
}
else
{
Console.WriteLine("you have issued this book :{0}", iss);
}
}
}
class program
{
static void Main(string[] args)
{
shuru:
gain_info obj = new gain_info();
try {
obj.get_info();
}
catch(book e)
{
Console.WriteLine("exception caught ",e.Message);
}
goto shuru;
}
}
}
OUTPUT

