Compartir a través de


Advertencia del compilador (nivel 1) CS1058

Actualización: noviembre 2007

Mensaje de error

Una cláusula catch previa ya detecta todas las excepciones. Las excepciones producidas se incluirán en System.Runtime.CompilerServices.RuntimeWrappedException
A previous catch clause already catches all exceptions. All exceptions thrown will be wrapped in a System.Runtime.CompilerServices.RuntimeWrappedException

Este atributo genera la advertencia CS1058 si un bloque catch() no tiene ningún tipo de excepción especificado después de un bloque catch (System.Exception e). La advertencia informa de que el bloque catch() no detectará ninguna excepción.

Un bloque catch() después de un bloque catch (System.Exception e) puede detectar las excepciones que no son CLS si RuntimeCompatibilityAttribute está establecido en false en el archivo AssemblyInfo.cs: [assembly: RuntimeCompatibilityAttribute(WrapNonExceptionThrows = false)]. Si este atributo no está establecido explícitamente en false, todas las excepciones generadas que no sean CLS se ajustarán como Exceptions y el bloque catch (System.Exception e) las detectará. Para obtener más información, vea Cómo: Detectar excepciones no compatibles con CLS.

Ejemplo

El código siguiente genera el error 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.
   }
}