各位,问题如上述所示,示例代码如下:
public virtual sbyte[] decodeBytes(QRCodeImage qrCodeImage)
{
    
    if (results.Count == 0)
       throw new DecodingFailedException("Give up decoding");
}下面是自定义的一个异常:
using System;
namespace ThoughtWorks.QRCode.ExceptionHandler
{

[Serializable]
    public class DecodingFailedException : System.ArgumentException
{
        internal String message = null; public override String Message
{
get
{
return message;
}

}

public DecodingFailedException(String message)
{
this.message = message;
}
}
}本人对异常实在有些雾水,还请各位指点一二,不胜感激。

解决方案 »

  1.   

    你再调用这个方法public virtual sbyte[] decodeBytes(QRCodeImage qrCodeImage) 的地方捕获DecodingFailedException这个异常,然后写文件不就行了
    try{
    decodeBytes()
    }
    catch(DecodingFailedException e){
    log(...)
    }
      

  2.   


    try
    {
       // ......
    }
    catch (Exception ex) { textBox1.Text = ex.ToString(); }
      

  3.   

    可以自己写个读写txt类
    也可以用一些log工具 比如 log4net就比较简单适用 功能也比较多
      

  4.   

    Catch住异常,处理,不要再throw
      

  5.   

    问题表述不是很明白,public virtual sbyte[] decodeBytes(QRCodeImage qrCodeImage)这个函数是在一个类中,并且函数有返回值,如果这样的话,该怎样进行?
      

  6.   

    lz是想在throw new DecodingFailedException时候就把异常显示到某TextBox中吧?那我觉得在DecodingFailedException的构造函数里写就可以了嘛
      

  7.   

    有没有返回值有关系吗?所有函数都有返回值啊...void也有啊
      

  8.   

    楼主既然有抛出异常,那当然就要有捕捉异常与处理相关异常的操作哈
    参考
     private int stringToInt(string source)
            {
                int result = 0;
                if (!Int32.TryParse(source, out result))
                {
                    throw new LoginException(source);//这里抛出异常
                }            return result;
            }
      try
                {
                    stringToInt("dfdf");
                }
                catch (LoginException ex)//这里捕捉异常
                {
                    //处理异常                Response.Write(ex.Title);            }
      

  9.   

     private int stringToInt(string source)
            {
                int result = 0;
                if (!Int32.TryParse(source, out result))
                {
                    throw new LoginException(source);//方法里面抛出异常
                }            return result;
            } protected void Page_Load(object sender, EventArgs e)
            {            try
                {
                    stringToInt("dfdf");
                }
                catch (LoginException ex)
                {
                    //处理异常
                    Response.Write(ex.Title);            }
    }
      

  10.   


    try
    {
        // ...
    }
    catch (Exception ex)
    {
        // 写到文件中
        StreamWriter sw = File.AppendText(@"c:\err.txt");
        sw.WriteLine(ex.ToString());
        sw.Flush();
        sw.Close();
    }
      

  11.   


    那你就不要try、catch,直接要它报错,终止程序的运行。
    你要处理异常,又要程序停止运行,呵呵,这个倒是第一次碰到,等待高手。
      

  12.   

    try
    {
        // ...
    }
    catch (Exception ex)
    {
        // 写到文件中
        StreamWriter sw = File.AppendText(@"c:\err.txt");
        sw.WriteLine(ex.ToString());
        sw.Flush();
        sw.Close();
    }这个写的对
      

  13.   

    楼上写错误日志是个不错的想法。ding!!