Code Snippet —— Try & Catch Block At Release

一个代码段,利用#if,使在Debug状态下时,try/catch关键字不会被编译,异常将被抛出;在Releae状态下时,try/catch关键字会被编译,程序可截获异常。
使用此代码有利于调试。
代码
<? xml version="1.0" encoding="utf-8"  ?>
< CodeSnippets   xmlns ="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet" >
    
< CodeSnippet  Format ="1.0.0" >
        
< Header >
            
< Title > re </ Title >
            
< Shortcut > re </ Shortcut >
            
< Description > Exception Snippet For Release </ Description >
            
< Author > Yedaoq </ Author >
            
< SnippetTypes >
                
< SnippetType > Expansion </ SnippetType >
                
< SnippetType > SurroundsWith </ SnippetType >
            
</ SnippetTypes >
        
</ Header >
        
< Snippet >
            
< Declarations >
                
< Literal >
                    
< ID > ExceptionMes </ ID >
                    
< ToolTip > Message to show when exception </ ToolTip >
                    
< Default > 出现异常! </ Default >
                
</ Literal >
            
</ Declarations >
            
< Code  Language ="csharp" >
                
<![CDATA[ #if !DEBUG
            try
#endif
            {
                $end$;
            }
#if !DEBUG
            catch (Exception ex)
            {
                MessageBox.Show("$ExceptionMes$", "提示");
            }
            finally
#endif
            {
                
            }
]]>
            
</ Code >
        
</ Snippet >
    
</ CodeSnippet >
</ CodeSnippets >




                            

你可能感兴趣的:(catch)