PC Review


Reply
Thread Tools Rate Thread

creating a custom exception

 
 
hharry
Guest
Posts: n/a
 
      1st Sep 2006
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 ?

 
Reply With Quote
 
 
 
 
Brian Gideon
Guest
Posts: n/a
 
      1st Sep 2006
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

 
Reply With Quote
 
hharry
Guest
Posts: n/a
 
      1st Sep 2006
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) ?

 
Reply With Quote
 
Carl Daniel [VC++ MVP]
Guest
Posts: n/a
 
      1st Sep 2006
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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Exception Raj Microsoft C# .NET 3 16th Oct 2009 06:39 AM
Creating custom Message Form. Issue with custom Icon Abhishek Tripathi Microsoft Outlook Form Programming 0 1st Dec 2008 11:39 AM
Creating a custom function to interpret another custom engine func Ryan Microsoft Excel Programming 0 3rd Mar 2008 07:18 PM
displaying exception message from custom exception bdgreen@pacbell.net Microsoft ASP .NET 2 18th Aug 2006 06:59 PM
Creating custom tasks with drop-down, formulas and custom text fie =?Utf-8?B?SmFz?= Microsoft Outlook Discussion 1 1st Jul 2005 11:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:35 PM.