1. Error Trapping
- Posted by Ferlin <ferlin at SANDW.NET> May 12, 1999
- 479 views
Hello All, A while back I left a message on this list about trapping errors in euphoria, it seems like someone (Can't seem to remember who) replied with some source code on how to accomplish the task. In some languages there is a Trap() function or On_Error() function to accomplish what I need, but I can't seem to find the code that was left or any thing similar. Here's the situation, I have a procedure such as: global procedure My_Procedure(sequence Obj) puts(1,"You sent " & Obj & " to My_Procedure") end procedure If the procedure is called like this My_Procedure(buffer) all is fine, but if it is called like this My_Procedure() the program BOMBS with My_Procedure() needs 1 arguments, not 0 I would like to capture this Error and perform and Error Routine, rather than have the program stop. This is just a quick example, but I would like to Trap different kinds of Errors. If euphoria doesn't have a function to do this, then MAYBE Rob could add it to the Wish List :) Thanks in Advance, + + + Rev. Ferlin Scarborough - Centreville, Alabama - USA email: ferlin at sandw.net email: ferlin at email.com
2. Re: Error Trapping
- Posted by Bernie Ryan <bwryan at PCOM.NET> May 12, 1999
- 464 views
>>global procedure My_Procedure(sequence Obj) >> puts(1,"You sent " & Obj & " to My_Procedure") >>end procedure -- You don't need trap global procedure My_Procedure(sequence Obj) -- take some corrective action or return and error condition if obj = {} then return -1 end if puts(1,"You sent " & Obj & " to My_Procedure") end procedure bernie
3. Re: Error Trapping
- Posted by Lewis Townsend <keroltarr at HOTMAIL.COM> May 12, 1999
- 459 views
- Last edited May 13, 1999
Bernie Ryan <bwryan at PCOM.NET> wrote: >-- You don't need trap > >global procedure My_Procedure(sequence Obj) > > -- take some corrective action or return and error condition > if obj = {} then > return -1 > end if I don't think that {} (an empty sequence) is equivalent to no value being passed to a routine. It still should bomb out when nothing is passed to it. Confirmation? Lewis Townsend _______________________________________________________________ Get Free Email and Do More On The Web. Visit http://www.msn.com
4. Re: Error Trapping
- Posted by "Boehme, Gabriel" <gboehme at POBOXB1.HQ.MSMAIL.MUSICLAND.COM> May 12, 1999
- 440 views
Ferlin wrote: > In some languages there is a Trap() function or On_Error() >function to accomplish what I need, but I can't seem to find the >code that was left or any thing similar. Well, there *is* a routine which allows you to leave a message on the screen in the event of an abend -- see LIBRARY.DOC for info on crash_message(). However, I don't believe Euphoria has the error-handling techniques you describe above. > Here's the situation, I have a procedure such as: > >global procedure My_Procedure(sequence Obj) > puts(1,"You sent " & Obj & " to My_Procedure") >end procedure > > If the procedure is called like this My_Procedure(buffer) >all is fine, but if it is called like this My_Procedure() > > the program BOMBS with My_Procedure() needs 1 arguments, not 0 > >I would like to capture this Error and perform and Error Routine, rather >than have the program stop. [snip] The problem here is that this is a *compile*-time error, not a run-time error. Euphoria doesn't even let this get past the compile step, since it "knows" that My_Procedure is supposed to take exactly *one* argument. So you couldn't trap this error with a routine even if you wanted to. >This is just a quick example, but I would >like to Trap different kinds of Errors. [snip] Perhaps if you gave us more examples describing the other kinds of errors you'd like to trap for? Be seeing you, Gabriel Boehme ------ The way we describe our world shows how we think of our world. How we think of our world governs how we interpret our world. How we interpret our world directs how we participate in it. How we participate in the world shapes the world. Robert Fripp ------
5. Re: Error Trapping
- Posted by "Boehme, Gabriel" <gboehme at POBOXB1.HQ.MSMAIL.MUSICLAND.COM> May 12, 1999
- 454 views
Bernie Ryan wrote: [in response to Ferlin's question about calling My_Procedure() with no arguments] >>global procedure My_Procedure(sequence Obj) >> puts(1,"You sent " & Obj & " to My_Procedure") >>end procedure > > -- You don't need trap > >global procedure My_Procedure(sequence Obj) > > -- take some corrective action or return and error condition > if obj = {} then > return -1 > end if > > puts(1,"You sent " & Obj & " to My_Procedure") > >end procedure In this example, a call to My_Procedure() with no arguments will not even get past the compile stage, so your "corrective action" will not have the effect you intended. The empty sequence {} is *not* equivalent to "no argument passed" -- Euphoria requires the programmer to specify *all* of a routine's parameters on each call, even when you're calling them with call_func() or call_proc(). [ADDITIONAL NITPICKY POINTS: Your "if" statement would result in the "true/false condition must be an ATOM" error. It should read "if equal(Obj, {})" or "if compare(Obj, {}) = 0" instead. Also, My_Procedure can't return a -1, because it's a procedure -- not a function.] Be seeing you, Gabriel Boehme ------ What amuses me is that Picard has to ask for 'Tea. Earl Grey. Hot.' This seems to mean: 1) The default value for Tea for the replicator is 'Cold'. 2) If he didn't specify 'Tea' then the Earl Grey himself would materialise on the tray. How many 18th century English noblemen were brought into existence before Jean-Luc worked that one out. Lance Parkin ------
6. Re: Error Trapping
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> May 13, 1999
- 456 views
> [ADDITIONAL NITPICKY POINTS: Your "if" statement would result in the > "true/false condition must be an ATOM" error. It should read "if equal(Obj, > {})" or "if compare(Obj, {}) = 0" instead. Also, My_Procedure can't return a > -1, because it's a procedure -- not a function.] Finally, at least, a correct reply after so many "you should use single qoutes" .. if v[i] = "" then .. and .. if v[i] = '' then Are both as incorrect as hell. The problem is the recursive nature of all mathimatical and relational operators, I suggest Robert wrote a seperate 'mini' - tutorial on the subject. Most of all newcomers to Euphoria have problems with this, and explenations such as: -- "you should use single qoutes" -- "you should use equal" etc. First of all, both replies assume some algorimic meaning of the program (and thus take the programming part out of the hands of the programmer), and lack the explenation *why* .. The problem isn't in the syntax of the program, its in the understanding of the programmer. And that will remain a problem until somebody explains how this works .. somebody asks "why isn't this working" and half of the people are like "let me do it for you" .. the list-server community is really great and helpfull to many people, but it wouldn't hurt any one if we would give it some thought and what exactly would and would not be helpfull. This way all our good intentions can have the effect we want it to have. At the end of this mail is a post I made on the newsgroup on the very same topic. It should explain this stuff for now (in my lousy Engish), but I suggest Robert adds a couple of mini-tutorials to the Euphoria packagae, that explain these kind of things. Topics I had in mind: -- Atom VS sequence (In appending, slicing, concationation) -- Recursive nature of mathimatical & relational operators -- Simple file I/O -- How to time a certain routine/technique -- Windows: a simple how-to do win32 (list of resources, a quick intro to win32lib or the new Liama) -- Data management (client/server) The last topic I will explain a bit futher: I meant the flow of data. Use local variables to store everything ? Return all information ? Return a handle. In other words, a quick how-to setup store information handle-based, etc. (basic techniques used by almost all libraries managing some kind of data) Off course, some one else could make such tutorials, but I at least suggest to pack such tutorials with the standard Euphoria package. Now here's the post about the recursive stuff, in my own lacking English.. Michael Dauth <mdauth at bigfoot.com> wrote in message news:7GNTflH8WwB at mdauth.bigfoot.com... > Hi, > > after banging my head for hours I found out that the "=" > operator does not work with sequences, but the equal functions > does. Am I wrong and if what am I doing if the following code > does not work: Indeed, totally correct. If-statements use any legal euphoria express to represent the TRUE / FALSE value, however Euphoria's rules about expression (the recursive operator 'theme') allow it in some occasions to generate a sequence rather than an atom value. Sequence is not clearly TRUE or FALSE, therefor the if-statement generates an error message in such case. So how do the Euphoria evaluation does work ? atom a, b, c a = 1 b = 0 c = not a ? c -- 0 c = a or b ? c -- 1 c = a and b ? c -- 0 sequence d, e, f d = { 1, 0, 1 } e = { 0, 1, 1 } f = not d ? f -- { 0, 1, 0 } f = d or e ? f -- { 1, 1, 1 } f = d and e ? f -- { 0, 0, 1 } object g, h, i g = 1 h = { 0, 1, 0 } i = not g ? i -- 0 i = not h ? i -- { 1, 0, 1 } i = g or h ? i -- { 1, 1, 1 } i = g and h ? i -- { 0, 1, 0 } sequence j, k, l j = { 1, 0, 0 } k = { 0, 1 } l = j or k ? l -- { { 1, 1 }, { 0, 1 }, { 0, 1} } l = j and k ? l -- { { 0, 1 }, { 0, 0 }, { 0, 0 } } -- What applies to the boolean operators also applies to the mathematical operators. -- Example: object m, n m = { 1, 2, 3 } n = m * 2 ? n -- { 2, 4, 6 } n = m * m ? n -- { 1, 4, 9 } n = m * { 1, 2, 3, 4 } ? n -- { { 1, 2, 3 }, { 2, 4, 6 }, { 3, 6, 9 } } -- In short terminology: -- Operators recurse whenever the either one of the two values is an atom or when the two sequences are of different length. So, since a string / qouted-sequence is handled just like any other sequence, the 'equal' _operator_ will recurse the equal-operation. You could write a recursive function like this to deal with it: global function equal (object x, object y) if atom (x) then if atom (y) then return x = y else return 0 end if elsif atom (y) then return 0 elsif length(x) != length(y) then return 0 else for index = 1 to length(x) do if not equal (x[index], y[index]) then return 0 end if end for return 1 end if end function But, guess what ? Its already built-in, and called precisely the same. You also have compare, but unlike the equal function which will only return an atom true / false value, compare returns either zero, minus one and plus one. Example: atom o, p o = 1 p = 2 ? compare (o, p) --- 1 ? compare (p, o) --- -1 ? compare (o, o) --- 0 ? compare (p, p) --- 1 I hope this was helpful, I always feel examples show more than words alone, nevertheless, feel free to ask for more explanation if any part is unclear. Good luck learning Euphoria .. Ralf Nieuwenhuijsen ... mailto://nieuwen at xs4all.nl ... mailto://ralf_n at email.com ... http://www.xs4all.nl/~nieuwen ... uin: 9389920
7. Re: Error Trapping
- Posted by "C. K. Lester" <cklester at TICNET.COM> May 13, 1999
- 441 views
At 03:26 PM 5/13/99 +0200, you wrote: > >Finally, at least, a correct reply after so many "you should use single >qoutes" .. > You'll note, however, that the "single quote" thingie solved his problem.
8. Re: Error Trapping
- Posted by Colin Taylor <cetaylor at COMPUSERVE.COM> May 13, 1999
- 438 views
Message text written by Ralf: >object m, n m =3D { 1, 2, 3 } ... n =3D m * { 1, 2, 3, 4 } ? n -- { { 1, 2, 3 }, { 2, 4, 6 }, { 3, 6, 9 } } < Sorry, Ralf. You can't do that. Colin
9. Re: Error Trapping
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> May 13, 1999
- 452 views
> At 03:26 PM 5/13/99 +0200, you wrote: > > > >Finally, at least, a correct reply after so many "you should use single > >qoutes" .. > > > > You'll note, however, that the "single quote" thingie solved his problem. It didn't. It just made his program work. Not the same thing, is it ? Ralf
10. Re: Error Trapping
- Posted by "Boehme, Gabriel" <gboehme at POBOXB1.HQ.MSMAIL.MUSICLAND.COM> May 13, 1999
- 446 views
Ralf Nieuwenhuijsen wrote: >if v[i] = "" then > >.. and .. > >if v[i] = '' then > >Are both as incorrect as hell. Yes, because the original post you seem to be responding to ["Rob questions"] had a space between the quotes. (And BTW, there's no such thing as a '' char in Euphoria -- you'll get a "single-quote char is empty" error.) >The problem is the recursive nature of all mathimatical and relational >operators, I suggest Robert wrote a seperate 'mini' - tutorial on the >subject. This might not be a bad idea. Almost every other language allows the use of "=" comparisons between strings in "if" statements, and remembering *not* to do so in Euphoria can be difficult. Perhaps a "new Euphoria programmer's list of tips" might be helpful -- brief overviews of Euphoria's major differences from other languages, with links or references to the appropriate section(s) of the manual for further explanation. Of course, as with the current Euphoria docs, the person has to actually *read* this new document, which doesn't always happen... >somebody asks "why isn't this working" and half of the people are like >"let me do it for you" .. the list-server community is really great and >helpfull to many people, but it wouldn't hurt any one if we would give >it some thought and what exactly would and would not be helpfull. For the most part, I think the people answering questions here on the list do a good job of giving *some* reasoning behind their solutions. As far as "what exactly would and would not be helpful," replies are only helpful when they are at least factually correct. >object m, n >m = { 1, 2, 3 } > >[snip] > >n = m * { 1, 2, 3, 4 } >? n -- { { 1, 2, 3 }, { 2, 4, 6 }, { 3, 6, 9 } } If you had actually executed the above code segment, you would quickly have discovered the following error message: "sequence lengths are not the same (3 != 4)" You can only do arithmetic operations on two atoms, an atom and a sequence, or two sequences of the exact same length (these rules apply recursively to every element of a sequence). From REFMAN.DOC, section 2.2.4 (Operations on sequences), paragraph three: "If a binary (two-operand) operator has operands which are both sequences THEN THE TWO SEQUENCES *MUST* BE OF THE SAME LENGTH." [emphasis mine -- perhaps this should also be emphasized in the manual, since I skipped right over it the first time through] And, from this very ListServ: ---------- From: Boehme, Gabriel Subject: Re: each keyword Date: Thursday, April 22, 1999 7:33PM Ralf Nieuwenhuijsen wrote: > [snip] Try print (1, {1,2,3} * {1,2,3}) >Euphoria, as an exception, or to be consistent (choose), will do the >following, because the two sequence are of the same length. > >{1, 4, 9} It's not the exception -- it's the rule. >But what when they are not of the same length ? > >print (1, {1,2,3} * {1,2,3,4}) The program abends with a "sequence lengths are not the same" error message. ---------- As I, too, have learned the hard way: it's always a good idea to actually check your examples before you post them. :) Be seeing you, Gabriel Boehme ------ None of the modern machines, none of the modern paraphernalia... have any power except over the people who choose to use them. G.K. Chesterton ------
11. Re: Error Trapping
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> May 15, 1999
- 445 views
> Ralf Nieuwenhuijsen wrote: > > >if v[i] = "" then > > > >.. and .. > > > >if v[i] = '' then > > > >Are both as incorrect as hell. > > Yes, because the original post you seem to be responding to ["Rob > questions"] had a space between the quotes. (And BTW, there's no such thing > as a '' char in Euphoria -- you'll get a "single-quote char is empty" > error.) It was precisely that error I was talking about. (My mistake though: there was a space between the qoutes) > Of course, as with the current Euphoria docs, the person has to actually > *read* this new document, which doesn't always happen... True, although most actually will read the docs when they get stuck. Esspecially when they remember there are sections about esspecially those situations. >> >somebody asks "why isn't this working" and half of the people are like > >"let me do it for you" .. the list-server community is really great and > >helpfull to many people, but it wouldn't hurt any one if we would give > >it some thought and what exactly would and would not be helpfull. > > For the most part, I think the people answering questions here on the list > do a good job of giving *some* reasoning behind their solutions. As far as > "what exactly would and would not be helpful," replies are only helpful when > they are at least factually correct. That last sentence is a pun. Thank you. No really I do agree, on the other hand, isn't it in every body's interest if such vague parts of Euphoria get discussed ? I simple wanted to start up, what imho is a usefull discussion. > >object m, n > >m = { 1, 2, 3 } > > > >[snip] > > > >n = m * { 1, 2, 3, 4 } > >? n -- { { 1, 2, 3 }, { 2, 4, 6 }, { 3, 6, 9 } } > > If you had actually executed the above code segment, you would quickly have > discovered the following error message: > > "sequence lengths are not the same (3 != 4)" See how vague even I am on the subject ? I was pretty sure it worked did way, but never bothered to try it out. Ralf
12. Error Trapping
- Posted by Ferlin <ferlin at SANDW.NET> Feb 25, 1999
- 435 views
All, Is there a way to trap errors in Euphoria? I am working on a project that involves an index of procedures and functions, the problem I am having is when someone enters the name of a function, if they do not have the proper number of parameters for that particular function Euphoria Issues an Error and aborts the program. Is there a way I could trap this parameters error and issue and error message? If not I guess I will have to include the number of parameters in the index for each function. BTW I am using a sequence for the index and routine_id() and call_func or call_proc to call these routines, got the idea from EUSERVE? works like a charm. Any and All HELP would be greatly appreciated. Later all: + + + Rev. Ferlin Scarborough - Centreville, Alabama - USA email: ferlin at sandw.net email: ferlin at email.com
13. Re: Error Trapping
- Posted by Bernie Ryan <bwryan at PCOM.NET> Feb 26, 1999
- 447 views
Why is'nt your input routine monitoring the users input and watching the number and type of parmameters ???? Bernie
14. Re: Error Trapping
- Posted by "Boehme, Gabriel" <gboehme at MUSICLAND.COM> Feb 26, 1999
- 456 views
Ferlin <ferlin at SANDW.NET> wrote: > Is there a way to trap errors in Euphoria? I am working >on a project that involves an index of procedures and functions, the >problem I am having is when someone enters the name of a function, if >they do not have the proper number of parameters for that particular >function Euphoria Issues an Error and aborts the program. Is there a >way I could trap this parameters error and issue and error message? This is a good question. Currently, when you get a routine_id(), you have to know in advance how many parameters it requires, what their types are, and whether the routine is a procedure or a function. I think it would be kinda neat if there were another function added to the routine_id() family: s = routine_info(id) Where s would be a sequence containing the relevant data: R_TYPE = 1, -- integer value indicating if this is a -- procedure or a function R_PROCEDURE = 1, R_FUNCTION = 2, R_PARM_DATA = 2 -- sequence containing the routine id's of all the -- parameter types for this routine -- number of parms = length(s[R_PARM_DATA]) Obviously, this kind of thing would at least require the built-in types (atom(), sequence(), etc.) to return valid routine_id() values, so that the R_PARM_DATA sequence always gives us valid routine id's. With this kind of thing available, it would be possible to completely verify all aspects of a user-entered routine -- how many parameters, what kind of parameters, and if we should expect a return value. Gabriel Boehme
15. Re: Error Trapping
- Posted by Ferlin <ferlin at SANDW.NET> Feb 26, 1999
- 442 views
"Boehme, Gabriel" wrote: > > > s = routine_info(id) > > Where s would be a sequence containing the relevant data: > > R_TYPE = 1, -- integer value indicating if this is a > -- procedure or a function > R_PROCEDURE = 1, > R_FUNCTION = 2, > > R_PARM_DATA = 2 -- sequence containing the routine id's of all the > -- parameter types for this routine > -- number of parms = length(s[R_PARM_DATA]) > I like the sound of this idea, and to me it looks elegant enough to fit into the current Euphoria Language Syntax, it is consistent with some of the other functions. + + + Rev. Ferlin Scarborough - Centreville, Alabama - USA email: ferlin at sandw.net email: ferlin at email.com
16. Re: Error Trapping
- Posted by Ralf Nieuwenhuijsen <nieuwen at XS4ALL.NL> Feb 27, 1999
- 482 views
>"Boehme, Gabriel" wrote: >> >> >> s = routine_info(id) >> >> Where s would be a sequence containing the relevant data: >> >> R_TYPE = 1, -- integer value indicating if this is a >> -- procedure or a function >> R_PROCEDURE = 1, >> R_FUNCTION = 2, >> >> R_PARM_DATA = 2 -- sequence containing the routine id's of all the >> -- parameter types for this routine >> -- number of parms = length(s[R_PARM_DATA]) >> > >I like the sound of this idea, and to me it looks elegant enough to fit >into the current Euphoria Language Syntax, it is consistent with some of >the other functions. A library follows. (i wanne hear 'thank you' .. All you have to do now, is call either register_function or register_procedure tell the routine-id and those of its parameters and you're done. --- whatyouwant.e sequence rtypes, rdata global procedure register_function (integer rp, sequence rd) if rp > length(rtypes) then rtypes &= repeat (-1, rp-length(types) ) rdata &= repeat ("", rp-length(types) ) end if rtypes[rp] = R_FUNCTION rdata[rp] = rd end procedure global procedure register_function (integer rp, sequence rd) if rp > length(rtypes) then rtypes &= repeat (-1, rp-length(types) ) rdata &= repeat ("", rp-length(types) ) end if rtypes[rp] = R_PROCEDURE rdata[rp] = rd end procedure global function routine_info (integer rp) if rp > length(rtypes) then return -1 elsif rtype[rp] != -1 then return {rtypes[rp], rdata[rp]} else return -1 end if end function Ralf Nieuwenhuijsen nieuwen at xs4all.nl ralf_n at email.com Uin: 9389920