Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » DSDP - Real-Time Software Components (RTSC) » Re-throwing an error
Re-throwing an error [message #3895] Tue, 09 June 2009 16:04 Go to next message
Ramsey Harris is currently offline Ramsey Harris
Messages: 22
Registered: July 2009
Junior Member
Champs,

Is it safe to call Error_raise() on a signaled error block? Or might some state information from the previous error "leak" into the second error and invalidate its state?

For example, I have some code which requests memory. If the heap runs out of memory, it will raise an error. But this is a low level and very common operation. I would like to add a second error event to the error log which indicates who was requesting the memory.

packet = (RcmClient_Packet*)Memory_alloc(NULL, size, sizeof(Ptr), eb);

if (Error_check(eb)) {
Error_raise(eb, RcmClient_E_packetAllocFailed, size, 0);
goto leave;
}

Is this safe to do, or must I call Error_init() before raising the second error?

Thanks
~ Ramsey
Re: Re-throwing an error [message #3902 is a reply to message #3895] Wed, 10 June 2009 15:47 Go to previous messageGo to next message
Eclipse User
Originally posted by: bob.biosbob.biz

from what i can tell, calling Error_init (again!) will effectively reset
the error block.... [i seem to recall an Error_clear function from the
past, though its implementation was probably just a called to Error_init
and was therefore dropped]

as an alternative, however, the function below (which is passed 'eb')
could declare its *own* Error_Block on the stack; the latter Error_Block
would be passed to Memory_alloc and -- depending upon the outcome -- the
original 'eb' would be passed to Error_raise....

this approach would be *necessary* if this particular routine want to do
some cleanup *before* calling Error_raise on the original 'eb'.... why?
because 'eb' could be NULL and passing it to Memory_alloc could lead to
premature program termination....

this design also enforces the "one error per one error block" approach...

but still, you can reuse error blocks by simply calling Error_init (again!)


Ramsey Harris wrote:
> Champs,
>
> Is it safe to call Error_raise() on a signaled error block? Or might
> some state information from the previous error "leak" into the second
> error and invalidate its state?
>
> For example, I have some code which requests memory. If the heap runs
> out of memory, it will raise an error. But this is a low level and very
> common operation. I would like to add a second error event to the error
> log which indicates who was requesting the memory.
>
> packet = (RcmClient_Packet*)Memory_alloc(NULL, size, sizeof(Ptr), eb);
>
> if (Error_check(eb)) {
> Error_raise(eb, RcmClient_E_packetAllocFailed, size, 0);
> goto leave;
> }
>
> Is this safe to do, or must I call Error_init() before raising the
> second error?
>
> Thanks
> ~ Ramsey
Re: Re-throwing an error [message #3908 is a reply to message #3902] Wed, 10 June 2009 18:01 Go to previous messageGo to next message
Ramsey Harris is currently offline Ramsey Harris
Messages: 22
Registered: July 2009
Junior Member
Interesting idea, creating a local error block. Thanks for that.

But my original question was really just asking if its okay to call Error_raise() on a signaled error block *without* first calling Error_init(). I would rather not have to call Error_init() if I don't need to.

Thanks
~ Ramsey

Bob Frankel wrote:
> from what i can tell, calling Error_init (again!) will effectively reset
> the error block.... [i seem to recall an Error_clear function from the
> past, though its implementation was probably just a called to Error_init
> and was therefore dropped]
>
> as an alternative, however, the function below (which is passed 'eb')
> could declare its *own* Error_Block on the stack; the latter Error_Block
> would be passed to Memory_alloc and -- depending upon the outcome -- the
> original 'eb' would be passed to Error_raise....
>
> this approach would be *necessary* if this particular routine want to do
> some cleanup *before* calling Error_raise on the original 'eb'.... why?
> because 'eb' could be NULL and passing it to Memory_alloc could lead to
> premature program termination....
>
> this design also enforces the "one error per one error block" approach...
>
> but still, you can reuse error blocks by simply calling Error_init (again!)
>
>
> Ramsey Harris wrote:
>> Champs,
>>
>> Is it safe to call Error_raise() on a signaled error block? Or might
>> some state information from the previous error "leak" into the second
>> error and invalidate its state?
>>
>> For example, I have some code which requests memory. If the heap runs
>> out of memory, it will raise an error. But this is a low level and
>> very common operation. I would like to add a second error event to the
>> error log which indicates who was requesting the memory.
>>
>> packet = (RcmClient_Packet*)Memory_alloc(NULL, size, sizeof(Ptr), eb);
>>
>> if (Error_check(eb)) {
>> Error_raise(eb, RcmClient_E_packetAllocFailed, size, 0);
>> goto leave;
>> }
>>
>> Is this safe to do, or must I call Error_init() before raising the
>> second error?
>>
>> Thanks
>> ~ Ramsey
Re: Re-throwing an error [message #3914 is a reply to message #3908] Thu, 11 June 2009 21:48 Go to previous message
Sasha Slijepcevic is currently offline Sasha Slijepcevic
Messages: 90
Registered: July 2009
Member
Error_raise calls Error_init internally. Also, the docs state:
"If Error_raise is called more than once on an Error_Block object, the
previous error information is overwritten; only the last error is retained
in the Error_Block object."

http://rtsc.eclipse.org/cdoc-tip/xdc/runtime/Error.html#rais e

I guess we could explicitly say that Error_raise always call Error_init,
but on the other hand, that's not the only way to ensure that the
Error_Block object is completely overwritten by subsequent Error_raise
calls. Even now, Error_raise writes into each field of the Error_Block
object, so the call to Error_init is redundant.
I would rather leave docs as they are and leave the implementation details
out of the docs, in case that the internal call to Error_raise gets
removed to save a couple of cycles.
Previous Topic:XDC on Mac OS X
Next Topic:How to access a siblings config params?
Goto Forum:
  


Current Time: Thu Oct 23 20:39:00 GMT 2014

Powered by FUDForum. Page generated in 0.04920 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software