catch(Exception ex)
{
throw ex;
}如果是这样的话,那么异常会原样抛出,类型是一样的。但是我想在这里自己定义异常提示,但是已捕获的异常类型的message属性是只读的不可修改。
如果我throw new Exception("提示")的话,异常就变成Exception类型了。
有没有办法在这里new一个和ex一样类型的异常呢

解决方案 »

  1.   


            static void Main(string[] args)
            {
                try
                {
                    throw new System.IO.EndOfStreamException("aaaa");
                }
                catch (Exception ee)
                {
                    Type t = ee.GetType();
                    System.Reflection.Assembly a = System.Reflection.Assembly.GetAssembly(t);
                    //object o = a.CreateInstance(t.FullName);
                    object oo = a.CreateInstance(t.FullName, false, System.Reflection.BindingFlags.CreateInstance, null, new object[] { ee.Message }, null, null);
                    throw oo as Exception;
                }
            }自己也写的有点迷糊,throw出去的是转换为Exception的异常.外面在gettype()一下还是可以看到原来的类型.
    本人才疏学浅,不知道如何动态转换类型.