.net - Why can't I catch a generic exception in C#? -


I was testing a few units on code that could put many exceptions based on input, so I like something like the following code Tried: (Simplified for example)

  Fixed zero main (string [] args) {RunTest & lt; ArgumentException & gt; (); } Fixed zero runtime & lt; T & gt; () T: Exception, New () (Try to throw new T); // New logic option; - LT; - either does not work} Grip (T-Tex) {Console.WriteLine (" "Exception type");} Hold (Exception preceded by) {Console.WriteLine ("Caught General Exception");} Console. Read ();}  

But it is always " Caught by the general exceptions ", the hold (tech) handler will never work, it does not matter whether I throw T () or explicitly I can throw arguments (excerpts). Why is there any idea? Actually, I was surprised that I was able to use T in the grip section, but is it possible that this should not be done? Or at least one Compiler gives warning / error that says that this handler will never work?

My environment is the Visual Studio 2008 and 3.5 target framework.

UPDATE: I tried to do this Now command prompt Sector directly and then "Oyster print exception of" pass. So it seems that it is limited to running within Visual Studio. Could the specialty of Visual Studio's hosting process be?

The strange behavior here ...

The VS2k8 console app is the following:

try {new t (throw); } Grip (T-tex) {console. Weedline ("In the Exception type caught"); } Hold (Exception Preceded by) {Console.WriteLine ("Holding Common Exceptions"); }

In the results "caught ordinary exceptions" .

But, delete the (useless) variable with the catch statement:

  Try {New T (throw); } Hold (t) {console. Weidline ("In the Exception Type Taken"); } Catch (exception) {Console.WriteLine ("Caught General Exceptions"); }  

Result "Captured in exception type" !!!


Update :

Heyh ... its a bug:

Source? here.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -