Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Visual Studio 2010关于global::System.Exception的问题_C#_.net_Visual Studio 2010 - Fatal编程技术网

C# Visual Studio 2010关于global::System.Exception的问题

C# Visual Studio 2010关于global::System.Exception的问题,c#,.net,visual-studio-2010,C#,.net,Visual Studio 2010,不知何故,今天当我输入: try {} catch {} 我明白了: try { } catch (global::System.Exception ex) { } 但应该是: try { } catch (Exception ex) { } 会发生什么?如何返回到异常 如果将光标放在Main方法的大括号之间,键入try并按[TAB]两次,即触发代码段进行try/catch,则以下程序将导致global::System.Exception 因此-您是否在项目

不知何故,今天当我输入:

try {} catch {}
我明白了:

try 
{       
}
catch (global::System.Exception ex)
{
}
但应该是:

try 
{       
}
catch (Exception ex)
{
}

会发生什么?如何返回到异常

如果将光标放在
Main
方法的大括号之间,键入
try
并按[TAB]两次,即触发代码段进行try/catch,则以下程序将导致
global::System.Exception

因此-您是否在项目/引用的程序集中的某处定义了一个名为
Exception
的类,或者您是否定义了一个顶级命名空间
System
?其中一个,或两者的结合可能导致这种情况。还要注意,代码示例使用语句不列出任何
,因此这可能是一个影响因素

namespace ExceptioWuh
{
    class Program
    {
        static void Main(string[] args)
        {

        }
    }

    namespace System
    {
        class Exception : global::System.Exception
        {
        }
    }
}

没有名为
Exception
present的自定义类型会导致
catch
成为
catch(System.Exception)
,因此我认为这是一个非常特殊的场景造成的。

问题是什么?只是模板?你知道这两者在代码中有相同的含义,对吗?(假设您没有其他类型的异常
Exception
)实际问题是什么?如果您指的是语法差异;它们是一样的。您可以删除
gloabl::System.
部分以返回到
异常
@SamuelSlade问题是我没有更改内容,但我得到了gloabl::System。“为什么?”Terminador抱歉,我以为我理解这一点,但也许不理解。您是否在
catch(Exception ex)
处遇到编译器错误?@Terminador您“没有更改内容”是什么意思
global::System.Exception
Exception
(假设后者来自
System
命名空间)表示相同的类型。