c# creating and throwing exceptions
C#
class Student
{
public int StudentID { get; set; }
public string StudentName { get; set; }
}
[Serializable]
class InvalidStudentNameException : Exception
{
public InvalidStudentNameException()
{
}
public InvalidStudentNameException(string name)
: base(String.Format("Invalid Student Name: {0}", name))
{
}
}
class Program
{
static void Main(string[] args)
{
Student newStudent = null;
try
{
newStudent = new Student();
newStudent.StudentName = "James007";
ValidateStudent(newStudent);
}
catch(InvalidStudentNameException ex)
{
Console.WriteLine(ex.Message );
}
Console.ReadKey();
}
private static void ValidateStudent(Student std)
{
Regex regex = new Regex("^[a-zA-Z]+$");
if (!regex.IsMatch(std.StudentName))
throw new InvalidStudentNameException(std.StudentName);
}
}static void CopyObject(SampleClass original)
{
if (original == null)
{
throw new System.ArgumentException("Parameter cannot be null", "original");
}
}
Also in C#:
- Title
- format float to time c#
- Category
- C#
- Title
- class selector to property in asp net core dropdown
- Category
- C#
- Title
- unix time c#
- Category
- C#
- Title
- asp net mvc 5 return view from another controller
- Category
- C#
- Title
- winforms timer c#
- Category
- C#
- Title
- mouseposition unity
- Category
- C#
- Title
- how to do a messagebox in c#
- Category
- C#
- Title
- c# creating exceptions
- Category
- C#
- Title
- unity main texture not working
- Category
- C#
- Title
- how to use more than one condition in ef join
- Category
- C#
- Title
- how to go to other forms in C#
- Category
- C#
- Title
- unity vector3 smoothdamp not reaching target
- Category
- C#
- Title
- unity how to change the text on a button
- Category
- C#
- Title
- .net core session
- Category
- C#
- Title
- unity if gameobject exists
- Category
- C#
- Title
- first person camera controller unity
- Category
- C#
- Title
- validating file upload asp.net core mvc
- Category
- C#
- Title
- find gameobject with tag
- Category
- C#
- Title
- unity how to get transform scale
- Category
- C#
- Title
- unity get list length
- Category
- C#
- Title
- datatable return column names
- Category
- C#
- Title
- how to check if a value is inside an array c#
- Category
- C#
- Title
- call Textboxfor in cs
- Category
- C#
- Title
- asp list box
- Category
- C#
- Title
- c# foreach arra
- Category
- C#
- Title
- block wapalyzer from detecting codeigniter
- Category
- C#
- Title
- make camera follow character unity 2020
- Category
- C#
- Title
- round vector3 unity
- Category
- C#
- Title
- c# round number
- Category
- C#
- Title
- windows forms iterate through all controls
- Category
- C#
- Title
- how to make an array in csharp
- Category
- C#
- Title
- unity ai wander script
- Category
- C#
- Title
- c# print to console
- Category
- C#
- Title
- c# one line set
- Category
- C#
- Title
- ihttpactionresult to object c#
- Category
- C#
- Title
- How to search for a string from readline in c#
- Category
- C#
- Title
- unity detect any key
- Category
- C#
- Title
- c# typeof
- Category
- C#
- Title
- countdown script in unity
- Category
- C#
- Title
- c# image to byte array
- Category
- C#
- Title
- wpf make size fill all grid
- Category
- C#
- Title
- c# to vb.net
- Category
- C#
- Title
- membership get user id
- Category
- C#
- Title
- check connection c#
- Category
- C#
- Title
- how to add a list to observablecollection in c#
- Category
- C#
- Title
- if get key down unity
- Category
- C#
- Title
- how to get joypad axis input unity
- Category
- C#
- Title
- ignore fakeiteasy
- Category
- C#
- Title
- c# convert Unix time in seconds to datetime
- Category
- C#
- Title
- What is a class in c#
- Category
- C#
- Title
- C# get pc language
- Category
- C#
- Title
- get hash c#
- Category
- C#
- Title
- unity onselect gizmos wireframe
- Category
- C#
- Title
- cannot convert string to generic type c#
- Category
- C#
- Title
- unity making homing missile
- Category
- C#
- Title
- unity c# is not equal to
- Category
- C#
- Title
- c# linq join multiple conditions
- Category
- C#
- Title
- c# get hwid
- Category
- C#
- Title
- webclient c# example post
- Category
- C#
- Title
- How to make a function in C#
- Category
- C#
- Title
- c# arraylist
- Category
- C#
- Title
- max of array C#
- Category
- C#
- Title
- unity check when clicked on object
- Category
- C#
- Title
- how to put double quotes in a string c#
- Category
- C#
- Title
- unity print to console
- Category
- C#
- Title
- c# .net core memory cache
- Category
- C#
- Title
- c# inheritance constructor
- Category
- C#
- Title
- how to add an embedded resource in visual studio code
- Category
- C#
- Title
- Unity C# instantiate prefab
- Category
- C#
- Title
- unity input get axis
- Category
- C#
- Title
- math class C# exponents
- Category
- C#
- Title
- blazor wasm routable page in separate project
- Category
- C#
- Title
- c# ?
- Category
- C#
- Title
- convert base64 string to string c#
- Category
- C#
- Title
- c# implement ienumerable t
- Category
- C#
- Title
- cshtml foreach
- Category
- C#
- Title
- html hidden text
- Category
- C#
- Title
- toggle unity c#
- Category
- C#
- Title
- c# how to add newline on text box
- Category
- C#
- Title
- c# null conditional
- Category
- C#
- Title
- compile in one single exe c#
- Category
- C#
- Title
- unity c# change color of gameobject
- Category
- C#
- Title
- dictionary c#
- Category
- C#
- Title
- change sprite of gameobject unity
- Category
- C#
- Title
- how to raycast unit
- Category
- C#
- Title
- unity create primitive
- Category
- C#
- Title
- clear combobox c#
- Category
- C#
- Title
- how to declare 2d array in c#
- Category
- C#
- Title
- how to find the type of a object c#
- Category
- C#
- Title
- unity set material color
- Category
- C#
- Title
- how to exit a program in c#
- Category
- C#
- Title
- query associative table ef6
- Category
- C#
- Title
- unity c# get bool from another script
- Category
- C#
- Title
- Rigidbody.addforce
- Category
- C#
- Title
- c# get list of all class fields
- Category
- C#
- Title
- c# reverse string
- Category
- C#
- Title
- c list add element
- Category
- C#
- Title
- check if current time is in the morning c#
- Category
- C#
- Title
- c# remove last character from string
- Category
- C#
- Title
- transform.Translate movement
- Category
- C#