最常見的error handling technique就是使用Exception,在try + catch block裡面catch exception之後,可以進行exception log,或是,直接rethrow exception
PS: For the following examples, the error is caused by an overflow after the user clicks on a "Save" button
1. throw ne Exception("錯誤訊息:" + e.Message);
cannot preserve information regarding the origin of the error
2. throw new Exception("錯誤訊息" + e.ToString());
preserve the information regarding the origin of the error while generating lengthy message
3. throw new Exception("錯誤訊息 + e.Message", e);
passing e as an inner exception helps preserve information while creating concise message regarding the error
4. throw e;
cannot preserve information
沒有留言:
張貼留言