Avviso del compilatore (livello 1) CS1058

Aggiornamento: novembre 2007

Messaggio di errore

Una clausola catch precedente rileva già tutte le eccezioni. Tutte le eccezioni generate verranno sottoposte a wrapping in System.Runtime.CompilerServices.RuntimeWrappedException
A previous catch clause already catches all exceptions. All exceptions thrown will be wrapped in a System.Runtime.CompilerServices.RuntimeWrappedException

Questo attributo provoca l'avviso CS1058 se un blocco catch() non ha un tipo di eccezione specificato dopo un blocco catch (System.Exception e). L'avviso informa che il blocco catch() non intercetterà alcuna eccezione.

Un blocco catch() dopo un blocco catch (System.Exception e) è in grado di intercettare eccezioni non CLS se RuntimeCompatibilityAttribute è impostato su false nel file AssemblyInfo.cs: [assembly: RuntimeCompatibilityAttribute(WrapNonExceptionThrows = false)]. Se questo attributo non è impostato in modo esplicito su false, tutte le eccezioni non CLS generate verranno sottoposte a wrapping come eccezioni e il blocco catch (System.Exception e) le intercetterà. Per ulteriori informazioni, vedere Procedura: intercettare un'eccezione non CLS.

Esempio

Nell'esempio riportato di seguito viene generato l'errore CS1058.

// CS1058.cs
// CS1058 expected
using System.Runtime.CompilerServices;

// the following attribute is set to true by default in the C# compiler
// set to false in your source code to resolve CS1058
[assembly: RuntimeCompatibilityAttribute(WrapNonExceptionThrows = true)]

class TestClass 
{
   static void Main() 
   {
      try {}

      catch (System.Exception e) { 
         System. Console.WriteLine("Caught exception {0}", e);
      }

      catch {}   // CS1058. This line will never be reached.
   }
}