请问如何拦截 Exception 抛出的信息

LHRSoft 2006-12-24 12:05:56
如题, 我要拦截的是 Exception 抛出的信息, 要把它记录起来, 但是不要显示对话框, 不够可以加分.
...全文
212 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
LHRSoft 2006-12-24
  • 打赏
  • 举报
回复
不是, 如果我在一个异常里,
if(transferThread != null)
{
throw new AppException("transferThread Exception.");
}
然后我想拦截这个 AppException 不让它显示, 记录起来就好.
liujia_0421 2006-12-24
  • 打赏
  • 举报
回复
没太明白..

你所说的系统是指你自己做的系统吧..

在有可能出现异常的地方用try..catch捕获一下,然后记录,比如说写到日志里..


LHRSoft 2006-12-24
  • 打赏
  • 举报
回复
不是,我要拦截的是 Exception 的异常, 系统抛出来的,
believefym 2006-12-24
  • 打赏
  • 举报
回复
try catch,在catch里面记录
liujia_0421 2006-12-24
  • 打赏
  • 举报
回复
既然你抛出异常,那就在外层进行捕获啊..

比如:

try
{
if(transferThread != null)
{
throw new AppException("transferThread Exception.");
}
}
catch(Exception ex)
{
  //操作,比如说记录到日志中..
}


如果你是在一个方法中抛出的:
public void MyMethod()
{
if(transferThread != null)
{
throw new AppException("transferThread Exception.");
}
}

try
{
MyMethod();
}
catch(Exception ex)
{
//操作,比如说写到日志中.
}
believefym 2006-12-24
  • 打赏
  • 举报
回复
不是, 如果我在一个异常里,
if(transferThread != null)
{
throw new AppException("transferThread Exception.");
}
然后我想拦截这个 AppException 不让它显示, 记录起来就好.
-----------------------
既然throw了,就是交给外面处理了,你在调用这个代码的地方try catch不就可以了
比如
public void fun()
if(transferThread != null)
{
throw new AppException("transferThread Exception.");
}

那么你肯定会在某个地方调用这个fun方法
try
{
fun();
}
catch(Exception e)
{
//记录异常
}

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧