Nested exceptions

View: New views
4 Messages — Rating Filter:   Alert me  

Nested exceptions

by David Chisnall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I'm getting this warning from some of my code:

ERROR: Removing exception handler that is not on top of the stack.  
(You probably called return in an NS_DURING block.)

I am not calling return in an NS_DURING block, but I am raising an  
exception in one of these blocks (the parser throws an exception to  
the tokeniser, which then throws a more informative one including  
source locations).  Do I need to do something to remove the current  
handler from the stack before I do this?

David


_______________________________________________
Gnustep-dev mailing list
Gnustep-dev@...
http://lists.gnu.org/mailman/listinfo/gnustep-dev

Re: Nested exceptions

by Richard Frith-Macdonald-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 12 Jul 2008, at 13:35, David Chisnall wrote:

> Hi,
>
> I'm getting this warning from some of my code:
>
> ERROR: Removing exception handler that is not on top of the stack.  
> (You probably called return in an NS_DURING block.)
>
> I am not calling return in an NS_DURING block, but I am raising an  
> exception in one of these blocks (the parser throws an exception to  
> the tokeniser, which then throws a more informative one including  
> source locations).  Do I need to do something to remove the current  
> handler from the stack before I do this?

No, you don't ... If you are inside an NS_DURING block and throw an  
exception, the exception is caught by that block and goes to the  
NS_HANDLER at the end of the block, and the handler is the one on top  
of the stack and is removed at that point.

Most likely the warning is correct, but is referring to a  different  
NS_DURING block to the one you think it means ... ie an NS_DURING  
block in some code called indirectly be the code inside your NS_DURING  
block.  Maybe the problem is not even in your own code, but inside  
some library code you are calling.





_______________________________________________
Gnustep-dev mailing list
Gnustep-dev@...
http://lists.gnu.org/mailman/listinfo/gnustep-dev

Re: Nested exceptions

by David Chisnall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 12 Jul 2008, at 14:03, Richard Frith-Macdonald wrote:

>
> On 12 Jul 2008, at 13:35, David Chisnall wrote:
>
>> Hi,
>>
>> I'm getting this warning from some of my code:
>>
>> ERROR: Removing exception handler that is not on top of the stack.  
>> (You probably called return in an NS_DURING block.)
>>
>> I am not calling return in an NS_DURING block, but I am raising an  
>> exception in one of these blocks (the parser throws an exception to  
>> the tokeniser, which then throws a more informative one including  
>> source locations).  Do I need to do something to remove the current  
>> handler from the stack before I do this?
>
> No, you don't ... If you are inside an NS_DURING block and throw an  
> exception, the exception is caught by that block and goes to the  
> NS_HANDLER at the end of the block, and the handler is the one on  
> top of the stack and is removed at that point.
>
> Most likely the warning is correct, but is referring to a  different  
> NS_DURING block to the one you think it means ... ie an NS_DURING  
> block in some code called indirectly be the code inside your  
> NS_DURING block.  Maybe the problem is not even in your own code,  
> but inside some library code you are calling.

Sorry, I meant to say that I am throwing an exception in an NS_HANDLER  
block - I am not returning from inside NS_DURING or NS_HANDLER.

David


_______________________________________________
Gnustep-dev mailing list
Gnustep-dev@...
http://lists.gnu.org/mailman/listinfo/gnustep-dev

Re: Nested exceptions

by Richard Frith-Macdonald-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 12 Jul 2008, at 14:07, David Chisnall wrote:

>
> On 12 Jul 2008, at 14:03, Richard Frith-Macdonald wrote:
>
>>
>> On 12 Jul 2008, at 13:35, David Chisnall wrote:
>>
>>> Hi,
>>>
>>> I'm getting this warning from some of my code:
>>>
>>> ERROR: Removing exception handler that is not on top of the stack.  
>>> (You probably called return in an NS_DURING block.)
>>>
>>> I am not calling return in an NS_DURING block, but I am raising an  
>>> exception in one of these blocks (the parser throws an exception  
>>> to the tokeniser, which then throws a more informative one  
>>> including source locations).  Do I need to do something to remove  
>>> the current handler from the stack before I do this?
>>
>> No, you don't ... If you are inside an NS_DURING block and throw an  
>> exception, the exception is caught by that block and goes to the  
>> NS_HANDLER at the end of the block, and the handler is the one on  
>> top of the stack and is removed at that point.
>>
>> Most likely the warning is correct, but is referring to a  
>> different NS_DURING block to the one you think it means ... ie an  
>> NS_DURING block in some code called indirectly be the code inside  
>> your NS_DURING block.  Maybe the problem is not even in your own  
>> code, but inside some library code you are calling.
>
> Sorry, I meant to say that I am throwing an exception in an  
> NS_HANDLER block - I am not returning from inside NS_DURING or  
> NS_HANDLER.

I think the same applies ... if you are inside a hander block, then  
the handler for that block has already been removed ... so you should  
only get the error if, within the handler, you call some code which  
does a return from inside an exception block, so that when your  
exception is caught, the handler on top of the stack does not match  
your position.





_______________________________________________
Gnustep-dev mailing list
Gnustep-dev@...
http://lists.gnu.org/mailman/listinfo/gnustep-dev
LightInTheBox - Buy quality products at wholesale price!