假设我在两个不同的程序集中有以下两个类:
//in assembly A
public class TypeA {
// Constructor omitted
public void MethodA
{
try {
//do something
}
catch {
throw;
}
}
}
//in assembly B
public class TypeB {
public void MethodB
{
try {
TypeA a = new TypeA();
a.MethodA();
}
catch (Exception e)
//Handle exception
}
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,MethodA中的try-catch只是提升异常,但并没有真正处理它.在MethodA中使用try-catch是否有任何优势?换句话说,这种try-catch块之间是否存在差异,而根本不使用它?