日期:2014-05-18  浏览次数:20407 次

|M| 如何在我的类中return 掉当前的操作
PageLoad()
{
      if(!mybase.load())return;
      ...
      ...
}

mybase
public   bool   static   load()
{
        return   false;
}
上面是我程序这样写的
我想能不能这样
-------------------
PageLoad()
{
      mybase.load()
      ...
      ...
}

mybase
public   void   static   load()
{
        bool   i=false;
        if(i==false)
        {
                //在这里实现上面的功能,也就是让mybase.load()下面的程序不再执行
        }
}

------解决方案--------------------
public void static load()
{
bool i=false;
if(i==false)
{
....
return;
}
.....
}

------解决方案--------------------
return;
throw Exception都会跳出当前的函数
------解决方案--------------------
System.Web.HttpContext.Current.Response.End();
------解决方案--------------------
ui.page里引用了mybase
而mybase里要控制page的行为(return 掉他的所有上级操作)
不建议这么做
page的逻辑放在page里就好了
------解决方案--------------------
参考http://community.csdn.net/Expert/topic/5550/5550231.xml?temp=.5615045


private void button1_Click(object sender, EventArgs e)
{
try
{
f1();
}
catch (Ex1 ex)
{
Console.WriteLine(ex.Message);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}

}
private void f1()
{
throw new Ex1( "this is f1 abort ");
}

public class Ex1 : Exception
{
public Ex1(string str)
: base(str)
{ }
}