'exception'에 해당되는 글 2건

  1. 2008.04.27 [Prog] Avoid prematured exception handling...
  2. 2008.04.10 [C/C++] Abusing throwing exception drops performance severely.

[Prog] Avoid prematured exception handling...

Essay/Software 2008.04.27 22:33
[[ blog 이사 과정에서 정확한 posting날짜가 분실됨. 년도와 분기 정도는 맞지 않을까? ]]

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.

신고
tags : exception
Trackback 0 : Comment 0

[C/C++] Abusing throwing exception drops performance severely.

Language/C&C++ 2008.04.10 23:36
[[ blog 이사 과정에서 정확한 posting날짜가 분실됨. 년도와 분기 정도는 맞지 않을까? ]]

Throwing exception in C++ is very expensive operation. But, "try... catch..." itself doesn't drain performance if exception is not thrown. So, "Throwing exception" should not be used for just convenience in coding!! This should be used only to handle unexpected and not-often-raised exception!
신고
Trackback 0 : Comment 0