date:
2005-01-26
Author: floodzhu
Remarks:
Error phenomenon
The following code can cause a compilation error:
C: /Work/visualstudio/floodzhu/class1.cs (9): "floodzhu.common.exception" means "namespace", here should be "class"
Using system;
Namespace floodzhu.common.exception
{
///
/// Class1 summary description.
/// summary>
Public Class ConnecTexception: Exception
{
Public connectionException ()
{
//
// TODO: Add constructor logic here
//
}
}
}
2. Error reason
When the compiler performs lexical analysis, I follow the "Recent Priority" principle (the stack processing method: Advanced afterward (Filo)) Recently, you can find the system.exception, but it is too late.
3. Solution
The following methods can:
Place the use system; statement in the Namespace inside. (Do not recommend this way) Explicitly specify the class name, that is, the base class is written into system.exception to put the name of the namespace, such as floodzhu.common.exceptions
4. Other instructions
In the following cases, the same error will occur.
The following two files exist in the same project, or in different projects but second files are referenced (not required, just reference DLLs) The first file is in the DLL.
CONNECTIONEXCEPTION.CS:
Using system;
Namespace floodzhu.exception
{
///
/// Class1 summary description.
/// summary>
Public Class Connectexception: ApplicationException
{
Public connectionException ()
{
//
// TODO: Add constructor logic here
//
}
}
}
Messagebox.cs:
Using system;
Namespace floodzhu.common.MESSAGEBOX
{
///
/// TEST summary description.
/// summary>
Public Class MessageBox
{
Public messagebox ()
{
Try
{
}
Catch (Exception E)
{
}
}
}
}
The same compilation error message will appear when compiling the second file, as follows:
C: /Work/visualstudio/floodzhu/test.cs (15): "Floodzhu.exception" means "namespace", here should be "class"
The reason is that the compiler first finds floodzhu.common.MessageBox, found no exception, then find Floodzhu.common, find the following no exception, then find FLODZHU, find the exception namespace below, so error. I used to write a full name when I was wrong, I could write a full name. For example, for class system.windows.forms.textbox, you can write as follows:
Textbox TB1;
Forms.TextBox TB2;
Windows.Forms.Textbox TB3;
System.Windows.Forms.TextBox TB4;