* Re: In Exception ? [not found] <35214b7a.0@news.profinet.at> @ 1998-04-04 0:00 ` Paul Van Bellinghen 1998-04-07 0:00 ` John Herro 1998-04-05 0:00 ` Corey Ashford 1 sibling, 1 reply; 11+ messages in thread From: Paul Van Bellinghen @ 1998-04-04 0:00 UTC (permalink / raw) > >My problem: I want to establish a routine that is called out of normal >flow, or out of an exception handler. How can I get the knowledge whether I >am 'in' an exception (means in its processing) or not. Is there a sort of >function than can be coded like > > if in_exception_handler then > ... > else > ... > end if; > > Couldn't you just add a Boolean variable to your calling sequence that you set to TRUE if you call the procedure from an exception handler and FALSE if you call it from normal flow. Or else use an enumeration variable that is set to either EXCEPTION or NORMAL: -------------------------------------------------- Procedure Foo(...) is Type Calling_Source_Type is (Exception, Normal); Calling_Source : Calling_Source_Type . . Calling_Source := Normal; Handler (Calling_Source); Exception: Calling_Source := Exception; Handler (Calling_Source); -------------------------------------------------- Procedure Handler (From_Where : Calling_Source_Type) is . . if From_Where = Exception then . .. End IF; -------------------------------------------------- ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: In Exception ? 1998-04-04 0:00 ` In Exception ? Paul Van Bellinghen @ 1998-04-07 0:00 ` John Herro 0 siblings, 0 replies; 11+ messages in thread From: John Herro @ 1998-04-07 0:00 UTC (permalink / raw) pvanbell@mhv.net wrote: > Or else use an enumeration variable that is > set to either EXCEPTION or NORMAL: ... > Type Calling_Source_Type is (Exception, Normal); I bet it won't compile! For the same reason that none of these will compile: type Direction is (Forward, Reverse, Left, Right); type Tape_Command is (Play, Record, Stop, Fast_Forward, Rewind, Pause); type Chemical Element is (H, He, Li, Be, ...); -- Fails at Indium. type State is (AL, AK, AZ, AR, ...); -- Fails at Indiana and Oregon. Those darn reserved words bite you when you least expect it! On the other hand, I once saw a Fortran program that used IF for a variable name! (Fortran has keywords but no reserved words.) To make readability even worse, although the variable name implies integer, the variable was actually floating point! (It was the Intermediate Frequency in a radio.) I guess Ada's reserved words aren't so bad after all! In any event, the advice given is fine; just make a slight change to the spelling of "Exception." - John Herro Download the shareware AdaTutor program at http://members.aol.com/AdaTutor ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: In Exception ? [not found] <35214b7a.0@news.profinet.at> 1998-04-04 0:00 ` In Exception ? Paul Van Bellinghen @ 1998-04-05 0:00 ` Corey Ashford 1998-04-07 0:00 ` nabbasi 1 sibling, 1 reply; 11+ messages in thread From: Corey Ashford @ 1998-04-05 0:00 UTC (permalink / raw) Gerhard Auinger wrote in message <35214b7a.0@news.profinet.at>... >Hello, > >I'm a pretty unexperienced ada programmer (Ada83), therefore I hope not to >ask to stupid things. > >My problem: I want to establish a routine that is called out of normal >flow, or out of an exception handler. How can I get the knowledge whether I >am 'in' an exception (means in its processing) or not. Is there a sort of >function than can be coded like > > if in_exception_handler then > ... > else > ... > end if; Ada95 doesn't provide such a feature, I'm afraid. So you'll need a more complicated solution. If you aren't using more than one task, then a simple global variable counter which is incremented inside the handler and decremented after the handler should suffice. If the counter is equal to zero, you are not on the "thread" of an exception handler. You'll have to treat non-standard exits from exception handlers carefully (goto's, exit statements, return statements, etc.). If you are using more than one task, you need this information on a per-task basis. If your compiler supports Annex C, then you could use the task attribute feature to implement the per-task counter. Another possible implementation is to pass the a boolean down through the call chain which says whether or not you're in a handler. This could get ugly, of course. Good luck - Corey ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: In Exception ? 1998-04-05 0:00 ` Corey Ashford @ 1998-04-07 0:00 ` nabbasi 1998-04-07 0:00 ` Corey Minyard ` (3 more replies) 0 siblings, 4 replies; 11+ messages in thread From: nabbasi @ 1998-04-07 0:00 UTC (permalink / raw) In article <6g7fpc$l08$1@usenet.rational.com>, "Corey says... > > >>Gerhard Auinger wrote in message <35214b7a.0@news.profinet.at>... >>My problem: I want to establish a routine that is called out of normal >>flow, or out of an exception handler. How can I get the knowledge whether I >>am 'in' an exception (means in its processing) or not. Is there a sort of >>function than can be coded like >> >> if in_exception_handler then >> ... >> else >> ... >> end if; > >Ada95 doesn't provide such a feature, I'm afraid. So you'll need a more >complicated >solution. > >If you aren't using more than one task, then a simple global variable >counter >which is incremented inside the handler and decremented after the handler >should suffice. this takes care of synch. between tasks. but what about interrupts? an interrupt could occur anytime, and it also could establish an exception, and could end up in it , so this would lead to a race condition also on the global variable. I have not done this, but I assume one could attach an ada procedure to an interrupt, or in VMS language, an AST. similar synch. issues will show up between an interrupt and non-interrupt mode code flow, as between different tasks. I think Ada should have a function that tells one if they are in an exception handler or not. I know this is platform specific stuff, but that is the whole idea of using Ada, to hide platform specific things from the user. I remember that PLIon VMS had such a call in its run-time library, I could be wrong though. my 2 cents. Nasser ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: In Exception ? 1998-04-07 0:00 ` nabbasi @ 1998-04-07 0:00 ` Corey Minyard [not found] ` <Er1n22.24v@world.std.com> ` (2 subsequent siblings) 3 siblings, 0 replies; 11+ messages in thread From: Corey Minyard @ 1998-04-07 0:00 UTC (permalink / raw) Gerhard Auinger wrote in message <35214b7a.0@news.profinet.at>... >My problem: I want to establish a routine that is called out of normal >flow, or out of an exception handler. How can I get the knowledge whether I >am 'in' an exception (means in its processing) or not. Is there a sort of >function than can be coded like > > if in_exception_handler then > ... > else > ... > end if; This seems like a rather odd thing to need. In Ada, an exception is much like a goto, it is just an alteration in the flow of execution, really. The knowledge you speak of would increase exception handling time (you would need to update a task-specific variable) and I would expect it would be very rarely used. If you REALLY need to know this, I would suggest that in the functions you are calling, you either have separate functions for exception and non-exception versions, or you have a variable you pass in to tell it if it is from an exception handler or not. Since you know from the first call out of the exception handler if you are in the exception handler, this should work. This is thread-safe, unlike global variables and the like. -- Corey Minyard Internet: minyard@acm.org Work: minyard@nortel.ca UUCP: minyard@wf-rch.cirr.com ^ permalink raw reply [flat|nested] 11+ messages in thread
[parent not found: <Er1n22.24v@world.std.com>]
* Re: In Exception ? [not found] ` <Er1n22.24v@world.std.com> @ 1998-04-07 0:00 ` Robert Dewar 0 siblings, 0 replies; 11+ messages in thread From: Robert Dewar @ 1998-04-07 0:00 UTC (permalink / raw) In article <6gcjru$7im@drn.newsguy.com>, <nabbasi@earthlink.net.NOSPAM> wrote: >I think Ada should have a function that tells one if they are in an >exception handler or not. ... I disagree, this would be a poor design feature. It is hard to imagine any legitimate code that needs to violate abstraction interfaces in this manner. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: In Exception ? 1998-04-07 0:00 ` nabbasi 1998-04-07 0:00 ` Corey Minyard [not found] ` <Er1n22.24v@world.std.com> @ 1998-04-09 0:00 ` Mats Weber 1998-04-09 0:00 ` nabbasi 1998-04-09 0:00 ` Mats Weber 3 siblings, 1 reply; 11+ messages in thread From: Mats Weber @ 1998-04-09 0:00 UTC (permalink / raw) nabbasi@earthlink.net.NOSPAM wrote: > this takes care of synch. between tasks. but what about interrupts? > an interrupt could occur anytime, and it also could establish an > exception, and could end up in it , so this would lead > to a race condition also on the global variable. What do you mean by interrupt ? I think the above is wrong. I don't see how you can end up in an exception handler asynchronously. Asynchronous transfer of control is not defined in terms of exceptions (see RM 9.7.4). Or am I missing something ? (Ada 80 had an asynchronous transfer of control mechanism based on exceptions, but it never got implemented in a widespread compiler, and was removed form Ada 83). ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: In Exception ? 1998-04-09 0:00 ` Mats Weber @ 1998-04-09 0:00 ` nabbasi 1998-04-10 0:00 ` Larry Kilgallen 0 siblings, 1 reply; 11+ messages in thread From: nabbasi @ 1998-04-09 0:00 UTC (permalink / raw) In article <352D0231.E98A0106@elca-matrix.ch>, Mats says... > >nabbasi@earthlink.net.NOSPAM wrote: > >> this takes care of synch. between tasks. but what about interrupts? >> an interrupt could occur anytime, and it also could establish an >> exception, and could end up in it , so this would lead >> to a race condition also on the global variable. > >What do you mean by interrupt ? I think the above is wrong. > >I don't see how you can end up in an exception handler asynchronously. >Asynchronous transfer of control is not defined in terms of exceptions (see RM >9.7.4). Or am I missing something ? > well, let me give an example. in VMS land, you can schedule an AST to occur at some time (a timer) , an AST is a procedure that will "fire" and starts executing at a higher IPL (interrupt priority level) than normal code. Also, you can do an asynchronous IO (write to a disk), and give an address of a procedure to execute when that IO operation is really complete. Then this procedure will execute as an AST, and will interrupt whatever the user mode process was doing at that time. Now, an AST is a normal procedure in all other way, except it runs as a higher IPL, (it is like a call back routine, except is interrupts the process whenever it wants) and so this procedure can if it wants, establish an exception handler when it starts running, and it can if it wants divide by zero after that, and so you can end up in an exception handler that is called from an interrupt routine running at high IPL and asynchronous to whatever the normal code was doing, which could have been in an exception handler also at the same time. Now, as I said, I did not know if one can associate an Ada procedure with a system interrupt. i.e. in the VMS example, I do not know if one can make a VMS system service from Ada and pass an address of an Ada procedure to be called as an AST (say when the IO is completed). Since certainly one can call VMS system services from Ada (there is an Ada binding for that), I would think one can also do the above in Ada, but it been long time since I played on VMS so I can be wrong. This sort of thing on VMS is not uncommon (programming with AST's), and it is flexible also, but needs careful programming to avoid problems with synchronizations between normal flow of code, and the AST flow of code. Nasser ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: In Exception ? 1998-04-09 0:00 ` nabbasi @ 1998-04-10 0:00 ` Larry Kilgallen 0 siblings, 0 replies; 11+ messages in thread From: Larry Kilgallen @ 1998-04-10 0:00 UTC (permalink / raw) In article <6gkafp$p31@drn.newsguy.com>, nabbasi@earthlink.net writes: > Now, as I said, I did not know if one can associate an Ada procedure with > a system interrupt. i.e. in the VMS example, I do not know if one can > make a VMS system service from Ada and pass an address of an Ada procedure > to be called as an AST (say when the IO is completed). Since certainly > one can call VMS system services from Ada (there is an Ada binding for > that), I would think one can also do the above in Ada, but it been long > time since I played on VMS so I can be wrong. One can, indeed, do that, but DEC Ada recommends another approach. > This sort of thing on VMS is not uncommon (programming with AST's), and it is > flexible also, but needs careful programming to avoid problems with > synchronizations between normal flow of code, and the AST flow of code. A special AST_ENTRY construct allows the DEC Ada programmer to specify an AST routine, but have that routine executed in normal (non-AST) mode sometime after the AST fires. This allows use of the AST mechanism in concert with the synchronization rules of the Ada language. Larry Kilgallen ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: In Exception ? 1998-04-07 0:00 ` nabbasi ` (2 preceding siblings ...) 1998-04-09 0:00 ` Mats Weber @ 1998-04-09 0:00 ` Mats Weber 1998-04-09 0:00 ` nabbasi 3 siblings, 1 reply; 11+ messages in thread From: Mats Weber @ 1998-04-09 0:00 UTC (permalink / raw) nabbasi@earthlink.net.NOSPAM wrote: > I think Ada should have a function that tells one if they are in an > exception handler or not. I know this is platform specific stuff, but > that is the whole idea of using Ada, to hide platform specific things > from the user. I remember that PLIon VMS had such a call in its run-time > library, I could be wrong though. Would that function return True or False at --B in the code below ? And if it is called from a subprogram that is called form --A ? I think the concept of "being in an exception handler" is just not so easy to define well. begin ... --A exception when e => begin ... --B exception when f => ... end; end; ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: In Exception ? 1998-04-09 0:00 ` Mats Weber @ 1998-04-09 0:00 ` nabbasi 0 siblings, 0 replies; 11+ messages in thread From: nabbasi @ 1998-04-09 0:00 UTC (permalink / raw) In article <352D0352.A5C6D4BA@elca-matrix.ch>, Mats says... > >nabbasi@earthlink.net.NOSPAM wrote: > >> I think Ada should have a function that tells one if they are in an >> exception handler or not. I know this is platform specific stuff, but >> that is the whole idea of using Ada, to hide platform specific things >> from the user. I remember that PLIon VMS had such a call in its run-time >> library, I could be wrong though. > >Would that function return True or False at --B in the code below ? And if it >is called from a subprogram that is called form --A ? I think the concept of >"being in an exception handler" is just not so easy to define well. > >begin > ... --A >exception > when e => > begin > ... --B > exception > when f => > ... > end; >end; well, I was thinking in general terms, of an exception handler as a "procedure" that is called by the system when an exception occurs. May be if one stays within Ada, it might not be clear. but from a system point of view, it is very clear. When a procedure "establishes" a condition handler, an address of a function that is the handler is stored somewhere, in VMS land, each procedure frame contains an entry that contains the address of an expection handler established in that procedure. If the slot in the frame is zero, then there is no excpetion handler established for THAT procedure, and when an exception happens in that procedure (divid by zero, access violation etc..) the system will rewide the stack to the next frame, and will then look to see if there is an exception handler establised in that frame, and so on. So, to ask if one is in exception handler or not, the system will have to look at the stack and to trace to see if the caller of this procedure is an exception handler for some other procedure, (it will know if the address of the procedure is stored in the exception handler address slot in the call frame of the procedure that established it) . for some other system , depending on how exception handlers are designed, this might or might not be possible. I understand that in Ada, an exception handler is a block of code within a procedure, someone said that going to that block is like doing a goto, i.e. it is not a separate procedure. And so based on this, what I was thinking of might not apply to Ada. Nasser ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~1998-04-10 0:00 UTC | newest] Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <35214b7a.0@news.profinet.at> 1998-04-04 0:00 ` In Exception ? Paul Van Bellinghen 1998-04-07 0:00 ` John Herro 1998-04-05 0:00 ` Corey Ashford 1998-04-07 0:00 ` nabbasi 1998-04-07 0:00 ` Corey Minyard [not found] ` <Er1n22.24v@world.std.com> 1998-04-07 0:00 ` Robert Dewar 1998-04-09 0:00 ` Mats Weber 1998-04-09 0:00 ` nabbasi 1998-04-10 0:00 ` Larry Kilgallen 1998-04-09 0:00 ` Mats Weber 1998-04-09 0:00 ` nabbasi
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox