码迷,mamicode.com
首页 > 其他好文 > 详细

正则表达式查找未记录的异常

时间:2015-07-15 10:53:19      阅读:83      评论:0      收藏:0      [点我收藏+]

标签:

在旧代码中,有一些地方只是写了catch{} ,但没有把异常信息记录下来,导致了分析查找问题的原因过久,但手动去查找哪儿没有捕获异常,所需要花费的时间又太长,以前有写过一次,但后来丢了,现在又要用到,先蹩脚地记录下来,给自己用的

情景一:
catch (Exception ex)
{

}
=>
catch (Exception ex)
{
TxtLog.WriteException(string.Format("任务处理错误,错误信息:{0}", ex.Message), ex);
}
查找内容: [ ]+catch[ ]*\(Exception ex\)\n[ ]+\{\n[ ]+\n[ ]+\}
替换对象: catch (Exception ex)\n{\nTxtLog.WriteException(string.Format("任务处理错误,错误信息:{0}", ex.Message), ex);\n}


情景二:
catch (Exception ex)
{
}
=>
catch (Exception ex)
{
TxtLog.WriteException(string.Format("任务处理错误,错误信息:{0}", ex.Message), ex);
}
查找内容: [ ]+catch[ ]*\(Exception ex\)\n[ ]+\{\n[ ]+\}
替换对象: catch (Exception ex)\n{\nTxtLog.WriteException(string.Format("任务处理错误,错误信息:{0}", ex.Message), ex);\n}


情景三:
catch( )
{
}
=>
catch (Exception ex)
{
TxtLog.WriteException(string.Format("任务处理错误,错误信息:{0}", ex.Message), ex);
}
查找内容: [ ]+catch[ ]*\([ ]*\)\n[ ]+\{\n[ ]+\}
替换对象: catch (Exception ex)\n{\nTxtLog.WriteException(string.Format("任务处理错误,错误信息:{0}", ex.Message), ex);\n}


情景四:
catch( )
{}
=>
catch (Exception ex)
{
TxtLog.WriteException(string.Format("任务处理错误,错误信息:{0}", ex.Message), ex);
}
查找内容: [ ]+catch[ ]*\([ ]*\)\n[ ]+\{[ ]*\}
替换对象: catch (Exception ex)\n{\nTxtLog.WriteException(string.Format("任务处理错误,错误信息:{0}", ex.Message), ex);\n}

情景五:
catch
{
}
=>
catch (Exception ex)
{
TxtLog.WriteException(string.Format("任务处理错误,错误信息:{0}", ex.Message), ex);
}
查找内容: [ ]+catch[ ]*\n[ ]+\{[ ]*\}
替换对象: catch (Exception ex)\n{\nTxtLog.WriteException(string.Format("任务处理错误,错误信息:{0}", ex.Message), ex);\n}

情景六:
catch
{

}
=>
catch (Exception ex)
{
TxtLog.WriteException(string.Format("任务处理错误,错误信息:{0}", ex.Message), ex);
}
查找内容: [ ]+catch[ ]*\n[ ]+\{\n[ ]*\}
替换对象: catch (Exception ex)\n{\nTxtLog.WriteException(string.Format("任务处理错误,错误信息:{0}", ex.Message), ex);\n}

正则表达式查找未记录的异常

标签:

原文地址:http://www.cnblogs.com/maanshancss/p/4647525.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!