我有一个类似下面的捕获块:
catch (Exception e)
{
connection.Close();
return null;
}
我收到警告说'e'没有被使用。我不想用它。但是,如果我删除它,我会收到一个错误,说“类型预期”。该怎么办?
答案 0 :(得分:6)
catch
{
connection.Close();
return null;
}
答案 1 :(得分:1)
这样做:
try
{
//code to throw exception
}
catch(ArgumentNullException)
{
//do something in response to this exception
}
catch(Exception)
{
//catch the general exception
}
这可以让你捕捉到不同类型的异常,而不必像上面的Danny那样强调一切(对不起,我只是评论,评价还不够!)
答案 2 :(得分:0)
取出e