PRB: Compilation Errors When You Try to Catch a Common Language Runtime Exception Using Exception Class (327770)
The information in this article applies to:
- Microsoft Visual J# .NET (2002)
- Microsoft Visual J# .NET (2003)
This article was previously published under Q327770 SYMPTOMSWhen you try to catch a common language runtime exception by
using the Exception class in your Visual J# .NET application, you may receive the
following error messages during compilation: C:\MyJSharpConsoleApplication\Class1.jsl(1): Type 'Exception' is
imported by System and java.lang. Using the java.lang type -or-
C:\MyJSharpConsoleApplication\Class1.jsl(10): Exception
'System.Exception' is not caught and does not appear in throws
clause CAUSEWhen the namespace is not qualified before the Exception class, the Visual J# .NET compiler considers Exception as java.lang.Exception instead of as System.Exception in the catch block. With the Visual J# .NET compiler, you cannot
catch a common language runtime exception (that is, System.Exception) by using java.lang.Exception, and you receive the compilation error messages.RESOLUTIONTo resolve this problem, catch the common language runtime
exception by using System.Exception instead of by using Exception. The following sample code shows how to catch a common language
runtime exception by using System.Exception: package MyJSharpConsoleApplication;
import System.*;
public class Class1
{
public static void main(String[] args)
{
try
{
throw new System.Exception("New CLR Exception");
}
catch(System.Exception e)
{
System.Console.WriteLine(e.ToString());
}
finally
{
System.Console.Read();
}
}
} STATUS This
behavior is by design.REFERENCESFor more information, visit the following Microsoft
Developer Network (MSDN) Web sites:
Modification Type: | Major | Last Reviewed: | 8/7/2003 |
---|
Keywords: | kbCompiler kbprb kberrmsg kbJava KB327770 kbAudDeveloper |
---|
|