473,385 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

creating a custom exception

hello all,

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

public class dataProvException : ApplicationException
{
public dataProvException()
{
//
// TODO: Add constructor logic here
//
}

public dataProvException(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 1862
hharry wrote:
hello all,

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

public class dataProvException : ApplicationException
{
public dataProvException()
{
//
// TODO: Add constructor logic here
//
}

public dataProvException(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 ApplicationException. 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
ApplicationException 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 dataProvException object like this:
dataProvException myEx = new dataProvException("error text");

then, the constructor on the base class (ApplicationException) will be
called instead of the constructor on the derived class
(dataProvException) ?

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 dataProvException object like this:
dataProvException myEx = new dataProvException("error text");

then, the constructor on the base class (ApplicationException) will
be called instead of the constructor on the derived class
(dataProvException) ?
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
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...
15
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...
6
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. ...
0
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...
3
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
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...
17
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
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...
1
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.