Reply to post: Re: About time too

Please, no Moore: 'Law' that defined how chips have been made for decades has run itself into a cul-de-sac

doublelayer Silver badge

Re: About time too

There are good reasons for exceptions rather than error codes. The major reason is how easy it is to improperly handle the error. For most return types, there is only one indicator for an error: null. For some types, there is none at all. So you have to figure out the fragile system of different error codes and hope that nobody ever changes it. For example, a function which returns null and sets errno on an error but eventually changes the value it sets errno to or has a path you didn't find where it returns null but doesn't set errno, leaving you with an old value.

If you're particularly starved of resources, then skip exceptions as they bring some overhead along with them. In most cases, however, the benefits of exceptions as an error-handling technique outweigh the minor overhead. For the same reason, when you're operating in very little memory, you can do hackish structures to cram data into small spaces, but in anything else, use normal types which don't need to be chopped up every time they're used. This isn't just to make the process of writing the software easier, but also because a program that embraces simplicity is easier to debug than one which strives always for efficiency. Programs with straightforward structure are easier for someone new to edit than ones where you have to understand the original coder's spaghetti but it does run faster. If the original coder has any flaws, that ease is important to fixing things.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon