In general, handling exception smoothly is very difficult. So, in many software, there are lots of prematured routine for exception handling. My recommend is, "just put "Assert" instead of premature exception handling(henceforth PEH)".
PEH give noisy information when exception is occurred, because software crashes at unexpected place due to PEH (Not the place where exception is actually raised).
Let's see following codes.
... info = Get_personal_info(name); if(!info){ return SYS_Fail;} ... Personal_InfoT* Get_personal_info(char* name) { ... int index = Search_with_name(name); if(index < 0) {return NULL;} // fail. (exception handling part) ---- (*) ... }
In this case, the place where exception is raised at first is (*). But, to handling exception, this function returns just 'NULL'. And at caller, it also returns 'SYS_Fail'. OK. It's reasonable. But, in practice, handling all these returned error smoothly requires lots of costs. So, in many cases, this is handled prematurely. And eventually, this error leads to software crash at unexpected place.
So, again, my point is just put 'Assert'. After all, we should try to debug all errors. 'Assert' is very helpful in debug. And then, we should decide whether remaining as 'Assert' or handling exception later - usually, exception from IO should be handled. This is more efficient in my opinion.
'Essay > Software' 카테고리의 다른 글
[Prog] What is "good code"? (0) | 2008.11.22 |
---|---|
[Prog] Trade offs (0) | 2008.05.12 |
[Prog] Outputs should be separated from inputs at directory level. (0) | 2008.02.19 |
[Dev] Let's make schedule-history-table! (0) | 2007.11.25 |
[Dev] Required comments in change list. (0) | 2007.08.11 |