在C中的例外的缺點
部分感到困惑.指導使用的一個缺點是:
Exception safety requires both RAIIand different coding practices. Lotsof supporting machinery is needed tomake writing correct exception-safecode easy. Further, to avoid requiringreaders to understand the entire callgraph, exception-safe code mustisolate logic that writes topersistent state into a “commit”phase. This will have both benefitsand costs (perhaps where you’re forcedto obfuscate code to isolate thecommit). Allowing exceptions wouldforce us to always pay those costseven when they’re not worth
具體來說,我不明白的是:
(…) exception-safe code must isolatelogic that writes to persistent stateinto a “commit” phase.
和這個:
(…) perhaps where you’re forced toobfuscate code to isolate the commit (…).
我認為我不習慣使用“持久狀態”,“提交階段”,“模糊程式碼來隔離提交”.這很簡單的一些小的解釋,例子或這些術語的參考,可能是為什麼這是真的.
“寫入持久狀態”意思是粗略地“寫入檔案”或“寫入資料庫”.
“進入”提交“階段.大概意味著“立刻做所有的寫作”
“也許你被迫混淆程式碼來隔離提交”,這意味著大概是“這可能使程式碼難以閱讀”(稍微濫用“混淆”這個詞,這意味著刻意做一些難以閱讀的東西,而這裡他們的意思是不經意間地閱讀,但濫用可能是故意的,為了戲劇性的效果)
更詳細地說:“寫持久狀態”更密切地意味著“寫出一些永久媒體,關於這個物件的所有細節,這將是重建它所需要的”.如果寫入被異常中斷,那麼這些“寫出的細節”(即“持久狀態”)可能包含新狀態的一半和舊狀態的一半,當重新建立時,導致無效的物件.因此,寫狀態必須是一個不間斷的行為.
http://stackoverflow.com/questions/3312513/on-a-disadvantage-of-exceptions-in-c
本站文章除註明轉載外,均為本站原創或編譯
轉載請明顯位置註明出處:在C中的例外的缺點