Share via


컴파일러 경고(수준 1) CS1058

업데이트: 2007년 11월

오류 메시지

이전의 catch 절에서 이미 모든 예외를 catch합니다. 예외가 아닌 모든 throw된 항목은 System.Runtime.CompilerServices.RuntimeWrappedException에 래핑됩니다.
A previous catch clause already catches all exceptions. All exceptions thrown will be wrapped in a System.Runtime.CompilerServices.RuntimeWrappedException

catch (System.Exception e) 블록 다음에 나오는 catch() 블록에 예외 형식이 지정되어 있지 않은 경우 이 특성을 사용하면 CS1058이 발생합니다. 이 경고는 catch() 블록에서 어떤 예외도 catch하지 않음을 나타냅니다.

AssemblyInfo.cs 파일에서 [assembly: RuntimeCompatibilityAttribute(WrapNonExceptionThrows = false)]와 같이 RuntimeCompatibilityAttribute가 false로 설정되어 있으면 catch (System.Exception e) 블록 다음의 catch() 블록은 CLS 규격이 아닌 예외를 catch할 수 있습니다. 이 특성이 명시적으로 false로 설정되어 있지 않으면 CLS 규격이 아닌 모든 throw된 예외가 예외로 래핑되고 catch (System.Exception e) 블록에서 이를 catch합니다. 자세한 내용은 방법: CLS 규격이 아닌 예외 catch를 참조하십시오.

예제

다음 예제에서는 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.
   }
}