C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
.NET
ADO.NET
Android
ASP.NET
C#
Databases & DBA
Design Patterns & Practices
iOS
Java
OOP/OOD
SharePoint
Software Testing
Web Development
WPF
View All
1
Reply
What are custom exceptions in C#?
Rahul Pandey
12y
1.2k
0
Reply
Delete Row
Delete Column
Insert Link
×
Insert
Cancel
Embed YouTube Video
×
Width (%)
Height (%)
Insert
Cancel
Table Options
×
Rows
Columns
First row as header
Create Table
Insert Image
×
Selected file:
Alignment
Left
Center
Right
Select an image from your device to upload
Upload to Server
Cancel
Submit
Sometime we might required to provide run time error or exception which are not predefined by C# in that case we have to be go for custom exceptions for creating the custom exceptions declare one class and inherit from Application Exception because whatever the custom exception we are going to be create that should come in the category of Application Exception class which is inheriting Exception class (Base class for all the Exceptions) for Example see below code public partial class ExceptionEx4 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { try { int empSalary =10000 ; if (empSalary < 14000) { throw new SalaryException("Employee Salary Is too Low"); } } catch (SalaryException ex) { Response.Write(ex.CustomMessage); } } } public class SalaryException : ApplicationException { private string _customMessage; public string CustomMessage { get { return this._customMessage; } private set { this._customMessage = value; } } public SalaryException(string message) { this._customMessage = message; } } For learning more about similar tyes of questions you can prefer the below link
c# interview questions
Krishna Mohan
11y
0
What is a Jagged Array in C#?
What is a struct in C#?
Message