Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #72750

Re: Error handling in a parser (return value or setjmp)

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: Error handling in a parser (return value or setjmp)
Date Wed, 14 Oct 2015 11:02:04 +1300
Lines 52
Message-ID <d85datFlf7cU4@mid.individual.net> (permalink)
References <mvhqgq$28c$1@speranza.aioe.org> <87mvvmdihg.fsf@bsb.me.uk> <dbfb2a3c-67b7-42de-aeff-a87742edbcf4@googlegroups.com> <mvjake$fm3$1@speranza.aioe.org> <d851roFlf7cU2@mid.individual.net> <mvjo7n$hac$1@speranza.aioe.org> <d85bjpFlf7cU3@mid.individual.net> <mvju39$uu9$1@speranza.aioe.org>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net bNRy00ZAj8UsswINUvr4Cgshv6yOm6FpOPr9PGE6olhtRlzwXn
Cancel-Lock sha1:VG6vBlxUiM1037qVQm5KNtY4+UM=
User-Agent Mozilla/5.0 (X11; SunOS i86pc; rv:17.0) Gecko/17.0 Thunderbird/17.0
In-Reply-To <mvju39$uu9$1@speranza.aioe.org>
Xref csiph.com comp.lang.c:72750

Show key headers only | View raw


Morten W. Petersen wrote:
> On 13.10.2015 23:32, Ian Collins wrote:
>> Morten W. Petersen wrote:
>>> On 13.10.2015 20:46, Ian Collins wrote:
>>>> Morten W. Petersen wrote:
>>>>> On 13.10.2015 17:26, supercat@casperkitty.com wrote:
>>> [...]
>>>>>
>>>>> Is it possible to look back up in the call stack, to search for a given
>>>>> point and restore to that?
>>>>
>>>> If you want C++ like exception handling, you know whee to look!
>>>
>>> Hmm, no, I don't want to rely on C++. :)
>>>
>>> I found this thing though:
>>>
>>>      http://www.nicemice.net/cexcept/
>>>
>>> Which is a exception system for C.  So there are alternatives, I
>>> just have to find the best one.
>>
>> Be very wary of any exception system for C.  The C language does not
>> have specific support or writing exception safe code.  You will have to
>> code defensively assuming any place (possibly any function call) where
>> the code may "throw" could be an early return.  There isn't any way to
>> clean up the stack on a "throw", so unless you intend to do little more
>> than call exit() at the "catch" point, you are asking for trouble.  You
>> may as well just terminate when you hit an error.
>
> Well if it is a part of a library and a greater system, exit is not an
> option.

Which effectively says using an exception system for C is not an option.

> Is it maybe possible to do some very basic initialization, record
> where one is in the stack and then wipe/release everything after
> that point with setjmp/longjmp if an exception is raised?

Anything is possible, many things are more trouble than they are worth.

> As for coding defensively, lots of tests, and specifically tests
> that really "trash" parts of the code that one is unsure about
> should be OK.

By defensively I was referring to writing exception safe code, which in 
falls into the more trouble than it is worth category.  Writing 
exception safe code in languages with exception support requires care. 
In C it is very very hard.

-- 
Ian Collins

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Error handling in a parser (return value or setjmp) "Morten W. Petersen" <morphex@gmail.com> - 2015-10-13 04:33 +0200
  Re: Error handling in a parser (return value or setjmp) Ian Collins <ian-news@hotmail.com> - 2015-10-13 15:54 +1300
    Re: Error handling in a parser (return value or setjmp) "Morten W. Petersen" <morphex@gmail.com> - 2015-10-13 05:07 +0200
  Re: Error handling in a parser (return value or setjmp) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-13 14:07 +0100
    Re: Error handling in a parser (return value or setjmp) "Morten W. Petersen" <morphex@gmail.com> - 2015-10-13 16:17 +0200
    Re: Error handling in a parser (return value or setjmp) supercat@casperkitty.com - 2015-10-13 08:26 -0700
      Re: Error handling in a parser (return value or setjmp) "Morten W. Petersen" <morphex@gmail.com> - 2015-10-13 18:14 +0200
        Re: Error handling in a parser (return value or setjmp) Ian Collins <ian-news@hotmail.com> - 2015-10-14 07:46 +1300
          Re: Error handling in a parser (return value or setjmp) "Morten W. Petersen" <morphex@gmail.com> - 2015-10-13 22:06 +0200
            Re: Error handling in a parser (return value or setjmp) Ian Collins <ian-news@hotmail.com> - 2015-10-14 10:32 +1300
              Re: Error handling in a parser (return value or setjmp) "Morten W. Petersen" <morphex@gmail.com> - 2015-10-13 23:47 +0200
                Re: Error handling in a parser (return value or setjmp) Ian Collins <ian-news@hotmail.com> - 2015-10-14 11:02 +1300
                Re: Error handling in a parser (return value or setjmp) Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-10-14 18:32 +0000
                Re: Error handling in a parser (return value or setjmp) "Morten W. Petersen" <morphex@gmail.com> - 2015-10-15 12:28 +0200
                Re: Error handling in a parser (return value or setjmp) Ian Collins <ian-news@hotmail.com> - 2015-10-16 07:47 +1300
            Re: Error handling in a parser (return value or setjmp) Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-10-13 21:39 +0000
              Re: Error handling in a parser (return value or setjmp) "Morten W. Petersen" <morphex@gmail.com> - 2015-10-13 23:49 +0200
                Re: Error handling in a parser (return value or setjmp) supercat@casperkitty.com - 2015-10-13 15:03 -0700
                Re: Error handling in a parser (return value or setjmp) "Morten W. Petersen" <morphex@gmail.com> - 2015-10-14 01:16 +0200
                Re: Error handling in a parser (return value or setjmp) Geoff <geoff@invalid.invalid> - 2015-10-13 16:46 -0700
                Re: Error handling in a parser (return value or setjmp) "Morten W. Petersen" <morphex@gmail.com> - 2015-10-14 02:13 +0200
                Re: Error handling in a parser (return value or setjmp) Geoff <geoff@invalid.invalid> - 2015-10-13 19:10 -0700
                Re: Error handling in a parser (return value or setjmp) "Morten W. Petersen" <morphex@gmail.com> - 2015-10-14 04:27 +0200
                Re: Error handling in a parser (return value or setjmp) Ian Collins <ian-news@hotmail.com> - 2015-10-14 16:05 +1300
                Re: Error handling in a parser (return value or setjmp) "Morten W. Petersen" <morphex@gmail.com> - 2015-10-14 05:18 +0200
                Re: Error handling in a parser (return value or setjmp) Ian Collins <ian-news@hotmail.com> - 2015-10-14 16:31 +1300
                Re: Error handling in a parser (return value or setjmp) "Morten W. Petersen" <morphex@gmail.com> - 2015-10-14 05:44 +0200
                Re: Error handling in a parser (return value or setjmp) Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-10-15 12:06 +0000
                Re: Error handling in a parser (return value or setjmp) "Morten W. Petersen" <morphex@gmail.com> - 2015-10-15 16:08 +0200
                Re: Error handling in a parser (return value or setjmp) supercat@casperkitty.com - 2015-10-14 00:36 -0700
                Re: Error handling in a parser (return value or setjmp) "Morten W. Petersen" <morphex@gmail.com> - 2015-10-15 12:32 +0200
                Re: Error handling in a parser (return value or setjmp) Ian Collins <ian-news@hotmail.com> - 2015-10-14 11:06 +1300
                Re: Error handling in a parser (return value or setjmp) David Brown <david.brown@hesbynett.no> - 2015-10-14 00:10 +0200
                Re: Error handling in a parser (return value or setjmp) James Kuyper <jameskuyper@verizon.net> - 2015-10-13 19:08 -0400
              Re: Error handling in a parser (return value or setjmp) raltbos@xs4all.nl (Richard Bos) - 2015-10-14 11:37 +0000
                Re: Error handling in a parser (return value or setjmp) "Morten W. Petersen" <morphex@gmail.com> - 2015-10-15 12:34 +0200
                Re: Error handling in a parser (return value or setjmp) Ian Collins <ian-news@hotmail.com> - 2015-10-16 07:56 +1300
                Re: Error handling in a parser (return value or setjmp) "Morten W. Petersen" <morphex@gmail.com> - 2015-10-16 05:45 +0200
            Re: Error handling in a parser (return value or setjmp) James Kuyper <jameskuyper@verizon.net> - 2015-10-13 18:53 -0400

csiph-web