获取throw new exception抛出异常信息的问题

luoch2 2010-11-17 03:25:45
我现在有很多页面有throw new exception("msg=暂无数据!&type=2")等类似的异常抛出,
但我现在就是想把这个异常转化为Response.write("<script>alert('暂无数据!');history.go(-1)</script>")
弹出框的形式来显示;

我要怎么去获取这个msg和type的内容呢?

请问我要怎么实现???
...全文
1429 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
luoch2 2010-11-25
  • 打赏
  • 举报
回复
我要的正是四楼的解答,谢谢各位了
边城的刀声 2010-11-17
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 luoch2 的回复:]

因为里面有很多throw new exception("msg=...")
所以按照你的做法的话我要修改很多,工作量会很大
就是想能不能有一个接口或者之类的能够捕获并接收到throw new exception("msg=...")
然后再用Response.write();
[/Quote]
覆盖页面的Onerror的方法
protected override void OnError(EventArgs e)
{
Response.Write("出错了");

Server.ClearError();
//base.OnError(e);
}
  • 打赏
  • 举报
回复
在Application_Error事件中统一处理。

http://blog.csdn.net/luminji/archive/2009/10/15/4676330.aspx
luoch2 2010-11-17
  • 打赏
  • 举报
回复
因为里面有很多throw new exception("msg=...")
所以按照你的做法的话我要修改很多,工作量会很大
就是想能不能有一个接口或者之类的能够捕获并接收到throw new exception("msg=...")
然后再用Response.write();
DataBox-MDX 2010-11-17
  • 打赏
  • 举报
回复

public String OperatorFunction()
{
try
{
你的逻辑代码
}
catch//一旦你上面的逻辑代码出错就会运行catch里的代码
{
return "暂无数据";
}
return "你正确的返回值"
}

然后这是你的调用代码:

string Str=OperatorFunction();
if(Str=="暂无数据")
{
Response.write("<script>alert('暂无数据!');history.go(-1)</script>"):
}
else
{}
luoch2 2010-11-17
  • 打赏
  • 举报
回复
哪位高手帮我解决一下啊……

111,093

社区成员

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

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

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