473,661 Members | 2,440 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

creating a custom exception

hello all,

quick syntax question. i am writing a custom exception class and came
across an example:

public class dataProvExcepti on : ApplicationExce ption
{
public dataProvExcepti on()
{
//
// TODO: Add constructor logic here
//
}

public dataProvExcepti on(string msg) : base(msg)
{
//
// TODO: Add constructor logic here
//

}

}

in the second constructor, what is the purpose of : base(msg) ?
i understand that the base keyword ids used to access members of the
base class ?

Sep 1 '06 #1
3 1869
hharry wrote:
hello all,

quick syntax question. i am writing a custom exception class and came
across an example:

public class dataProvExcepti on : ApplicationExce ption
{
public dataProvExcepti on()
{
//
// TODO: Add constructor logic here
//
}

public dataProvExcepti on(string msg) : base(msg)
{
//
// TODO: Add constructor logic here
//

}

}

in the second constructor, what is the purpose of : base(msg) ?
i understand that the base keyword ids used to access members of the
base class ?
That calls a base class constructor. In this case you're passing the
exception message to a base class constructor that has one string
parameter.

Also, it is recommended to avoid the use of ApplicationExce ption. If I
remember correctly there was some discussion on whether or not to
deprecate it, but it doesn't appear that happened in 2.0. The idea was
that SystemException would be used for exceptions thrown by the CLR and
ApplicationExce ption would be used for non-CLR exceptions. The problem
is Microsoft didn't follow their own guideline so what seemed like a
good idea is nearly useless now.

http://blogs.msdn.com/kcwalina/archi...23/644822.aspx

Brian

Sep 1 '06 #2
thanks brian,

i'm testing this out now but if i've got this right:

if i initialize a new dataProvExcepti on object like this:
dataProvExcepti on myEx = new dataProvExcepti on("error text");

then, the constructor on the base class (ApplicationExc eption) will be
called instead of the constructor on the derived class
(dataProvExcept ion) ?

Sep 1 '06 #3
hharry wrote:
thanks brian,

i'm testing this out now but if i've got this right:

if i initialize a new dataProvExcepti on object like this:
dataProvExcepti on myEx = new dataProvExcepti on("error text");

then, the constructor on the base class (ApplicationExc eption) will
be called instead of the constructor on the derived class
(dataProvExcept ion) ?
The constructor of the derived class _calls_ the constructor of the base
class. Both will run.

-cd
Sep 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4742
by: Ken Allen | last post by:
I have a .net client/server application using remoting, and I cannot get the custom exception class to pass from the server to the client. The custom exception is derived from ApplicationException and is defined in an assembly common to the client and server components. The custom class merely defines three (3) constructors -- the null constructor; one with a string parameter; and one with a string and innner exception parameter -- that...
15
6743
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use javascript or vbscript it works. I will appreciate any help. I do the following (C#):
6
1577
by: Steve Amey | last post by:
Hi all I want to be able to throw a custom error up the call stack. I have looked around and it seems as though it's possible, but I can't get it to work :o( Below is some sample code. ------------------------------------------------------------ Public Class MainForm Public Sub Show Form Try
0
1124
by: thehitman | last post by:
I used an article "Creating a Flexible Configuration Section Handler "(http://www.15seconds.com/issue/040504.htm). The Console application works with app.config but with the web.config. The Namespace change and inserting into a class library are the only differences in the code. In the web config <!-- Config section Group and Sections Declaration --> <configSections> <section name="DropDownListTableSettings"
3
1716
by: Dan | last post by:
Hi all! When I throw my custom Exception class the first time in my code, the compiler takes a lot of time for find the following catch EX: try Throw New MyCustomException("test")
3
1912
by: CharlieC | last post by:
I am writing a windows C# application, and I want to ensure that all exceptions, handled or otherwise, are logged to the local event log. I can do this for the handled exceptions, but I am not sure how to override (?) the system exception such that un-handled exceptions are logged. I know that you can do this in delphi by pointing the application exception to your own base exception handler. Is there any similar way that this can be done...
17
1941
by: Lee Harr | last post by:
I understand how to create a property like this: class RC(object): def _set_pwm(self, v): self._pwm01 = v % 256 def _get_pwm(self): return self._pwm01 pwm01 = property(_get_pwm, _set_pwm)
3
3400
by: matko | last post by:
This is a long one, so I'll summarize: 1. What are your opinions on raising an exception within the constructor of a (custom) exception? 2. How do -you- validate arguments in your own exception constructors? I've noticed that, f.ex., ArgumentException accepts null arguments without raising ArgumentNullException. Obviously, if nothing is to be supplied to the exception constructor, the default constructor should
1
1639
by: Tony Johansson | last post by:
Hello! If I want to create my own Exception class which class is the recommended class to derive from. Should it be from Exception or from System.ApplicationException. //Tony
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8855
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8758
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7364
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1743
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.