c# creating 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);
}
}
Also in C#:
- Title
- C# move form without border
- Category
- C#
- Title
- math class C# exponents
- Category
- C#
- Title
- get set c#
- Category
- C#
- Title
- loop gridcontrol devexpress c#
- Category
- C#
- Title
- movement script c#
- Category
- C#
- Title
- c# combobox datasource enum
- Category
- C#
- Title
- foreach syntax c#
- Category
- C#
- Title
- same click event diffrenet buttonms c#
- Category
- C#
- Title
- unity get velocity at point
- Category
- C#
- Title
- c# .net core memory cache
- Category
- C#
- Title
- add variable to the beginning of a list c#
- Category
- C#
- Title
- c# retrieve files in folder
- Category
- C#
- Title
- application variable in asp.net core
- Category
- C#
- Title
- using in c#
- Category
- C#
- Title
- first person camera controller unity
- Category
- C#
- Title
- unity delete specific text in a string
- Category
- C#
- Title
- fahrenheit to celsius c#
- Category
- C#
- Title
- c# list all files in a directory and subdirectory
- Category
- C#
- Title
- how to add array to list in c#
- Category
- C#
- Title
- csharp first element of array
- Category
- C#
- Title
- unity load scene
- Category
- C#
- Title
- c# windows grab screenshot
- Category
- C#
- Title
- get first and last item list c#
- Category
- C#
- Title
- or in unity c#
- Category
- C#
- Title
- what is a protected int c#
- Category
- C#
- Title
- create line in unity
- Category
- C#
- Title
- array to list C
- Category
- C#
- Title
- how to do a messagebox in c#
- Category
- C#
- Title
- phone
- Category
- C#
- Title
- to list c#
- Category
- C#
- Title
- change z value unity
- Category
- C#
- Title
- unity monobehaviour
- Category
- C#
- Title
- c# instantiate
- Category
- C#
- Title
- downlaod file and use C#
- Category
- C#
- Title
- unknown discriminator value mongodb
- Category
- C#
- Title
- c# get every point in a line in matrix
- Category
- C#
- Title
- c# get desktop path
- Category
- C#
- Title
- c# multiple catch exceptions
- Category
- C#
- Title
- how to update a project to cross target .net core
- Category
- C#
- Title
- c# dictionaries
- Category
- C#
- Title
- asking for user input integer c#
- Category
- C#
- Title
- c# distinct comparer multiple properties
- Category
- C#
- Title
- C# .net core convert string to enum
- Category
- C#
- Title
- create new object from generic c#
- Category
- C#
- Title
- winforms timer c#
- Category
- C#
- Title
- how to allow user import image c#
- Category
- C#
- Title
- what data type should be for contact number in asp.net
- Category
- C#
- Title
- c# join string array
- Category
- C#
- Title
- sum of digits in c#
- Category
- C#
- Title
- c# string methods
- Category
- C#
- Title
- unity array c#
- Category
- C#
- Title
- c# region tag
- Category
- C#
- Title
- how to start an if statement in c#
- Category
- C#
- Title
- c# list string return concatenate
- Category
- C#
- Title
- c# pass mouse events to parent
- Category
- C#
- Title
- unity3d get component
- Category
- C#
- Title
- how to name GameObject in c#
- Category
- C#
- Title
- how to make a C# application visual studio code
- Category
- C#
- Title
- vb.net drag window without titlebar
- Category
- C#
- Title
- strtorime online
- Category
- C#
- Title
- how to make error sound c#
- Category
- C#
- Title
- unity get velocity of gameobject
- Category
- C#
- Title
- null coalescing operator c#
- Category
- C#
- Title
- exception handling c#
- Category
- C#
- Title
- Could not load file or assembly 'Ubiety.Dns.Core, Version=2.2.1.0
- Category
- C#
- Title
- check for collision unity c#
- Category
- C#
- Title
- how to get component in unity c#
- Category
- C#
- Title
- C# how to expose an internal class to another project in the solution
- Category
- C#
- Title
- iteration c#
- Category
- C#
- Title
- index in foreach c#
- Category
- C#
- Title
- convert string array to int C#
- Category
- C#
- Title
- Move player on planets in unity 2d
- Category
- C#
- Title
- How do i destroy a prefab without the error?
- Category
- C#
- Title
- c# object clone
- Category
- C#
- Title
- findobject getcomponent
- Category
- C#
- Title
- unity how to tell when a gameobject is colliding
- Category
- C#
- Title
- how to change an int value c#
- Category
- C#
- Title
- query into complex object using dapper
- Category
- C#
- Title
- xml node update attribute value c#
- Category
- C#
- Title
- how to add a gameobject
- Category
- C#
- Title
- leantween move ui
- Category
- C#
- Title
- unity remove parent
- Category
- C#
- Title
- unity accessing 2d pointlight from c# script
- Category
- C#
- Title
- how to change the title of the console in c#
- Category
- C#
- Title
- c# sort array string by length
- Category
- C#
- Title
- C# events
- Category
- C#
- Title
- roulette algorithm genetic algorithm
- Category
- C#
- Title
- console.writeline
- Category
- C#
- Title
- Assets\playermove.cs(30,37): error CS1003: Syntax error, ',' expected
- Category
- C#
- Title
- C# Console multi language
- Category
- C#
- Title
- c# date
- Category
- C#
- Title
- iframe set html content c#
- Category
- C#
- Title
- c# how to exit program
- Category
- C#
- Title
- c# substring reverse
- Category
- C#
- Title
- foreach as parallel c#
- Category
- C#
- Title
- c# new list object
- Category
- C#
- Title
- countdownevent
- Category
- C#
- Title
- c# string to lowercase
- Category
- C#
- Title
- unity get list length
- Category
- C#
- Title
- move towards target unity
- Category
- C#