calling base-constructor
-
hi, i'm designing an exception for my program and have the following problem. i want an additional constructor, which gets an int as paramter, builds a string out of it and calls the base-classes constructor with a string. something like
class MyException : ApplicationExcpetion
{
...
public MyException(int errorCode)
{
string message;
switch(errorCode)
{
case // blabla, setting message here correctly
default: message="unkown errorcode"; break;
}
base(message);
}
}but C# tells me: "Use of keyword base is not valid in this context" :( i'm stuck. anyone any idea? thx! :wq
-
hi, i'm designing an exception for my program and have the following problem. i want an additional constructor, which gets an int as paramter, builds a string out of it and calls the base-classes constructor with a string. something like
class MyException : ApplicationExcpetion
{
...
public MyException(int errorCode)
{
string message;
switch(errorCode)
{
case // blabla, setting message here correctly
default: message="unkown errorcode"; break;
}
base(message);
}
}but C# tells me: "Use of keyword base is not valid in this context" :( i'm stuck. anyone any idea? thx! :wq
You can only call the base constructor like the following.
class MyException: ApplicationException { pubilc MyException(int errorcode) : base ( MyException.GetErrorString(errorcode) ) { // Constructor logic } }
The base constructor can only be called in that location. Jared jparsons@jparsons.org www.prism.gatech.edu/~gte477n -
You can only call the base constructor like the following.
class MyException: ApplicationException { pubilc MyException(int errorcode) : base ( MyException.GetErrorString(errorcode) ) { // Constructor logic } }
The base constructor can only be called in that location. Jared jparsons@jparsons.org www.prism.gatech.edu/~gte477n -
You can only call the base constructor like the following.
class MyException: ApplicationException { pubilc MyException(int errorcode) : base ( MyException.GetErrorString(errorcode) ) { // Constructor logic } }
The base constructor can only be called in that location. Jared jparsons@jparsons.org www.prism.gatech.edu/~gte477nI would also prefer to be able to delay the base construction. Look at my case. class MyException: ApplicationException { int errorcode; pubilc MyException() { errorcode = GetErrorCode(); base ( MyException.GetErrorString(errorcode) ); } } Now I wouldnt have to call the GetErrorCode() function everytime when i need to throw it :) Maybe there is a way to pre-initialise some variables...:confused: MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D
-
I would also prefer to be able to delay the base construction. Look at my case. class MyException: ApplicationException { int errorcode; pubilc MyException() { errorcode = GetErrorCode(); base ( MyException.GetErrorString(errorcode) ); } } Now I wouldnt have to call the GetErrorCode() function everytime when i need to throw it :) Maybe there is a way to pre-initialise some variables...:confused: MYrc : A .NET IRC client with C# Plugin Capabilities. See http://sourceforge.net/projects/myrc for more info. :-D
leppie wrote: Maybe there is a way to pre-initialise some variable You could use a static constructor to preinitialize some variables. Jared jparsons@jparsons.org www.prism.gatech.edu/~gte477n