模拟一个主程序调类库时,异常处理的标准写法。 class Program { public int doit(int i,int j) { int result = 0; try { result = i / j; } catch { //这个Catch可以没有,例如:try{}finally{}就可以了。 throw; } finally { //释放资源 } return result; } static void Main(string[] args) { Program pro = new Program(); try { int result = 0; result = pro.doit(12, 0); } catch (Exception e) { //异常处理的动作 Console.WriteLine(e.Message); } finally { //释放资源 } }