lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Thu, Sep 11, 2014 at 2:38 PM, Sean Conner <sean@conman.org> wrote:
It was thus said that the Great William Ahern once stated:
> On Thu, Sep 11, 2014 at 09:50:29AM -0400, Sean Conner wrote:
> > It was thus said that the Great Andrew Starks once stated:
> <snip>
> > > Are there interesting differences between how you think about / deal with
> > > error handling in C/C++ vs. Lua?  Accepting that the mechanisms are
> > > different, do you do more "try to recover" code in C?
> >
> >   I don't program in C++, so I don't use exceptions.  In regard to error
> > handling, I tend to handle errors in Lua like I do in C.  And I don't really
> > do "recover" code in C.  [2][3]
> >
>
> What do you mean by recover? Surely you handle errors like EMFILE and ENOMEM
> without exiting the process.

  How would *you* handle ENOMEM?

  I wrote a big on this a few years ago:

        http://boston.conman.org/2009/12/01.2

  And depending upon the context, ENOMEM may be a case 3 (per the post) or
case 4.  I generally just stop processing if I get ENOMEM since I usually
have no idea how to handle the situation.

  Then again, I rarely encounter ENOMEM since Linux does overcommit by
default, so I'll see a SIGSEGV long before ENOMEM 8-P

> In C it helps if you use failure-free data structures as much as possible,
> which is why I never use list or tree implementations that do dynamic node
> allocation. Otherwise, you need to maintain additional state and write
> additional logic to handle partial rewinding of application state.

  So what do you do in C++?  Is the std::vector (however it's spelled, I'm
not a C++ programmer) failure-free?  Or the other default data structures
you get in C++ (or Boost)?

  -spc



I just read your blog post. Great stuff. It summarized the motivation behind my question.

1: My code looks great! Things are tidy and clean and commented. But there is no error checking, so this is just a prototype.
2: I'm getting tired of programming, because typing out these errors and checks for errors is a pain. now my code looks like crap and the mere process of doing this has led me to bloat it in other ways.

It's not a Lua problem, though.

--Andrew