首页 > 其他 > 详细

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

时间:2015-07-15 10:52:05      阅读:178      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!