[Prog] Avoid prematured exception handling…

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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s