Microsoft MVP성태의 닷넷 이야기
Debug : 8. RuntimeWrappedException 사용 이해 [링크 복사], [링크+제목 복사],
조회: 9680
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

Exception Handling Changes in C# 2.0
; http://mark.michaelis.net/Blog/ExceptionHandlingChangesInC20.aspx

.NET 1.0/1.1 까지만 해도 try / catch 로 잡을 수 있는 예외 유형은 오직 System.Exception에서만 파생되는 클래스만이 가능했습니다. 만약, System.Exception 에서 상속되지 않은 유형의 예외를 처리하고 싶다면 비어 있는 catch 블록 구문을 사용해야 했습니다.

예를 들어 다음과 같은 코드입니다.

using System;
class Program
{
     static void Main()
     {
          try
          {
               Console.WriteLine("Hello. My name is Inigo Montoya.");
          }
          catch(Exception)
          {
               // …
          }
          catch
          {
               Console.WriteLine("UNEXPECTED EXCEPTION");
          }
     }
}

하지만, .NET 2.0에서는 System.Exception 에서 파생되지 않은 예외가 발생한 경우에도 catch 가 가능하도록 System.Runtime.CompilerServices.RuntimeWrappedException 클래스가 새롭게 추가되었습니다. 따라서, 이제 더 이상 비어있는 catch 문을 사용하지 않고도 예외를 잡는 것이 가능해졌습니다. 또한 RuntimeWrappedException 클래스 자체도 System.Exception에서 파생되었기 때문에 이전의 비어있는 catch 문을 대신해서 "System.Exception"을 catch 해도 동일한 효과를 얻을 수 있습니다.

만약, .NET 2.0의 새로운 규칙을 따르지 않고 이전처럼 예외처리를 하고 싶다면 다음과 같은 특성을 적용하면 .NET 1.0/1.1 에서의 예외처리가 적용이 됩니다.

[assembly:System.Runtime.CompilerServices.RuntimeCompatibility(WrapNonExceptionThrows = false)]



[이 토픽에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 3/6/2007]


비밀번호

댓글 작성자
 




... 31  32  33  34  35  36  37  [38]  39  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
239정성태4/18/20069297Display a Web Page in a Plain C Win32 Application
238정성태4/17/20069298ASP.NET 2.0 의 Provider 관련 쪽 소스 공개
237정성태4/17/20069055Microsoft Application Verifier
236정성태4/17/200610202IIS6 - IE static resource caching problem
235정성태4/13/20068839"Atlas" Control Toolkit for April CTP Released
234정성태4/13/20069195Access Visual Studio 2005 Team System From Macintosh and UNIX Systems, and from within the Eclipse IDE
233정성태4/13/20068939More Workflow Videos
232정성태4/13/20069960Microsoft Visual C++ 2005 Redistributable Package
231정성태4/13/20069506Windows Presentation Foundation Hands-On-Labs - February 2006 CTP
230정성태4/13/20069358Microsoft Management Model Designer
229정성태4/13/200610403Discovery Wizard for SharePoint
228정성태4/13/20069963TeamPlain Web Access for Team System
227정성태4/13/20069681Scrum for Team System Released
226정성태4/13/20069674Visual Studio Team Foundation Server MSSCCI Provider Version 1.0
224정성태4/13/20069293VC++ - GroupLab Component Library
223정성태4/13/20068376MSBuild Community Tasks Project releases new version
225정성태4/13/20067821    답변글 Visual Studio 2005 Web Application Projects (RC1)
222정성태4/13/20068854Visual Studio 2005 Security Features and Tools
220정성태6/8/20068686Shared Source Common Language Infrastructure 2.0 Release [1]
219정성태8/4/20068598Simple List Extensions Specification
218정성태4/13/200691693rd party library - EZShellExtensions.Net 1.0 [1]
217정성태4/13/20069028Bug Details: GC fails to load in server mode if config file contains none ASCII characters
215정성태4/13/20069168http://www.400plusdifferences.com/
214정성태4/13/20067842Team Foundation Server, Biztalk 2006
216정성태4/13/20069093    답변글 Team Foundation Server 시험판 공개 다운로드
213정성태4/13/20069058Introduction to the MSN Messenger Activity SDK
... 31  32  33  34  35  36  37  [38]  39  40  41  42  43  44  45  ...