background preloader

C-Sharp

Facebook Twitter

Custom Exception Handling in C# Introduction Enhanced Exception Handling is one of key features that is most prominently available in .Net both 2003 version and Whidbey versions of C#.

Custom Exception Handling in C#

This paper discusses the implementation of Custom Exception Handling using the existing features of C# .Net. The Concept The whole idea of having customized Exception Handling is centered around the fact that there needs to be a generic approach of catching and throwing Exceptions. For implementing custom Exception Handling we need to derive the class CustomException from the system base class ApplicationException.

A custom exception class which would host the exception thrown and can be thrown as a new exception. Implementation The following are the steps that are required to implement custom exception for creation of the above mentioned components: Step 1: Define a project called Enumerators that would contain the definitions of all the Enumerators as the following: The Severity level determines the criticality of the error. Step 2: Step 3: Best Practices for Handling Exceptions. A well-designed app handles exceptions and errors to prevent app crashes.

Best Practices for Handling Exceptions

This article describes best practices for handling and creating exceptions. The following list contains some general guidelines for handling exceptions in your app. Use exception handling code (try/catch blocks) appropriately. You can also programmatically check for a condition that is likely to occur without using exception handling. In other situations, using exception handling to catch an error condition is appropriate. The following list contains guidelines for creating your own exceptions and when they should be raised.

Barcode

LINQ To XML Tutorials with Examples. A lot of developers over the past few months have requested us for tutorials focusing on LINQToXML.

LINQ To XML Tutorials with Examples

Although I have written a couple of them in the past, I decided to republish these tips in the form of a single post. In this article, we will explore 24 ‘How Do I’ kind of examples using LINQ to XML. I assume you are familiar with LINQ. If not, you can start off with LINQ by checking some tutorials over here and here. Subscribe to our Free Digital Magazines for .NET Professionals For this article, we will be using a sample file called ‘Employees.xml’ for all our samples which is available with the source code. <EmpId>1</EmpId> <Name>Sam</Name> <Sex>Male</Sex> <Phone Type="Home">423-555-0124</Phone> <Phone Type="Work">424-555-0545</Phone> .net Naming Conventions and Programming Standards - Best Practices.

This article is the single most popular bit of content from my old site and blog, bar none.

.net Naming Conventions and Programming Standards - Best Practices

While I think books such as the .NET Framework Design Guidelines by Krzystof Cwalina and Brad Abrams do a better job explaining all the standards, I've kept this page up for quick reference and to support the schools and individuals currently using it. Common .NET Naming Conventions These are the industry-accepted standard naming conventions for C# and VB.NET programs. For additional information, please see the MSDN help documentation and the book referenced above.

While individual naming conventions at organizations may vary (Microsoft only suggests conventions for public and protected items), the list below is quickly becoming the de-facto standard in the industry. Note that while this document predates the online and printed standards documentation from Microsoft, everything below which indicates it is based on .NET library standards is consistent with that documentation and Brad's book.

Log4Net Tutorial. There are various of logging solutions in general and specifically for .net.

Log4Net Tutorial

One of my favorite solutions is log4net, the .net port of log4j. I like the fact that log4net is free, supports multiple loggers, supports multiple log target types (“appenders”), supports multi-threaded scenarios, does not seem to affect performance and is usually easy to use. However, I noticed that usually at new projects, despite reusing log4net over and over, I have a hard time making it actually log something at first run. The thing is that log4net doesn’t seem to report any configuration issues, so it’s like a trial and error till you get it right. One other thing that I find missing in log4net, is a good real-time log viewer. In this post I’ll attempt to help with a quick “first time” successful log4net logging, and putting Log2Console to work. log4net Setting up log4net depends on writing a valid configuration file.

And now for the Logger wrapper class. The running code is self-explanatory: Log2Console.

WPF