A step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.
A C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.
This tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.
Creating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.
Creating custom exceptionsThis tutorial will show you how to create your own exceptions by using a class derived from System.ApplicationException. |
On Wednesday, July 28th 2004 at 07:41 AM By Andrew Pociu (View Profile) ![]() ![]() ![]() ![]() (Rated 3.2 with 25 votes) |
|||
|
This is the continuation of the tutorial named Handling and throwing exceptions. I recommend you read that tutorial first. In that tutorial, at the end you saw how to throw your own exceptions. Here will do the same thing, but a bit more complicated because now you'll be able to customize the exception. Create a new Console Application project named customExceptions in Microsoft Visual Studio .NET. First we'll have to create the class derived from System.ApplicationException:
As you can see, it's nothing more than a class derived from System.ApplicationException with a constructor that takes the msg as a parameter. Here's Class1 where we actually throw the exception if the user enters '0'.
The code is fully commented so I suppose you have no problem understanding it. Now let's compile it and enter '0' when prompted:
That's all. |
||||
Digg It!
Del.icio.us
Reddit
StumbleIt
Newsvine
Furl
BlinkList
|
||||
|
||||
Current CommentsThank you, it helped me...
A very simplistic approach that does not cover proper custom exception "manufacturing". In fact if you read Microsoft documentation you will see that they say you must derive your custom exceptions from System.Exception and NOT from System.ApplicationException.
You also missed here the default constructors and the serialization constraints.
But well, better than nothing at all.
Sorry to say that, but that's absolutely useless.
You can learn even more if you just use the Exception-Snippet in Visual Studio (Express)...
"Where there is a will, there is a way"
If you have been in software development for a while, you would agree that criticizing any code block can be easy. Let's be a little positive and appreciate the efforts of the author.
I did not meant the code being bad or unclean.
But you are right. It's good to have someone telling the new developers directions.
Sorry for this post above. I have matured myself :-)
yes indeed it is helping enough
The simplest tutorial i found !! gr8 :)
The simplest tutorial i found !! gr8 :)
Super mamau
If you don't provide constructive criticism developers are bound to commit (and enforce) errors over and over. There is much difference between a tutorial and a code snippet.
Anyway, if there are some that prefer to ignore the comments then sorry for the mistakes you are bound to commit now and in the future.
True said , but it's the way a comment is made important
For me, it was the KISS(Keep it Simple Stupid) rule that made me like this Tutorial
Related Tutorials
Related Source Code
C# Job Search