1. Robert Craig... One Wish Please

Hi Robert,

I have only one wish i would like added to exw. The ability to call a 
routine at crash time or in case of a windows exception, similar to what 
Matt lewis has done but built into the Euphoria interpreter/translator. 

     This is very handy when cleaning up GDI resources and Memory 
allocations made using API calls rather than EU Calls. Generally, this 
would help us clean-up and avoid reboots due to resource leaks.

How about that? WIN32 programmers back me up

jordah ferguson
Robert Craig wrote:
> Ricardo Forno writes:
> > 1) Comments C type: /* ... */ to ease commenting out code blocks.
> 
> I use F12 in ed to insert a bunch of comments.
> (Removing them is a bit harder.)
> In C, I find it strange that there are two different ways
> of commenting code. /* ... */ was the original way,
> then they added // to be more compatible with C++.
> I can never make up my mind which one to use, so
> I use both, almost at random. I'd rather stick to one
> consistent method.
> 
> > 2) Enhancements to the trace facility:
> > A) Variables should not be shown automatically but only at an user
> > request.
> 
> Why? What harm does it do to show a few variables on the screen
> automatically?
> 
> > B) Allow showing expressions, at least of the form x[i][k],
> > z[2..n], etc.
> 
> Yes, I'll probably do that in the next release.
> 
> > Better if all valid expressions were allowed, including
> > function calls.
> 
> True, but unfortunately it's extremely difficult to implement.
> 
> > c) On a more advanced mood, allow entering the editor while in trace
> > mode, defining and executing new routines, modifying old ones,
> > modifying and creating variables, etc.
> 
> That's hard too.
> 
> > 3) Allow executing string variables, that can 
> > contain code like "x = y * p".
> > 4) Allow defining functions from a string, for example:
> > "function foo(integer u) return power(u, u) end function"
> 
> I don't like any feature that requires code or variables to be 
> constructed
> at run-time and executed. I used this in APL, and found it
> was an overly-powerful solution searching desperately for a problem.
> Rarely useful in practice. Theoretically it buys you nothing
> in terms of the algorithms you can implement.
> It's also extremely hard to implement in the current interpreter
> without starting from scratch. Any translated to C code that
> used this feature would need to carry around a
> complete copy of the interpreter.
> 
> > 5) A function that returns the amount of available real storage at the
> > moment.
> > It will ease the task of determining the size of buffers to avoid
> > using virtual storage.
> 
> You could write a routine that calls allocate() with progressively
> smaller sizes until it doesn't get a 0 returned, although that
> wouldn't exclude virtual storage.
> 
> You might want to know the total free space, or you might want
> to know the largest contiguous block of storage that's available.
> 
> You'd also need to know how much space Euphoria variables
> consume. I don't like to make the implementation details
> of Euphoria's internal representation so explicit.
> In most Euphoria programming you shouldn't have to think
> in terms of bits, bytes and nibbles.
> 
> I might consider doing something, 
> but now that I have 256Mb RAM, 
> I don't expect to run out of memory very often.
> 
> > 6) A facility to save the status and variables 
> > of a program in the middle of
> > execution, also available from the trace screen. This will ease
> > debugging; you could advance execution to a certain point, save,
> > continue, and in case of failure, restart at the saved point.
> 
> Do you want me to undo all the changes that you've made to files?
> Set the screen back the way it was? Open and close windows, 
> undo the side effects of .dll routines that you've called, 
> memory that you've overwritten, etc.?
> 
> > 7) Add the following *internal* data types: byte, word (2 bytes), and
> > perhaps (why not?) bit and nibble (half byte), all in 
> > order to save storage.
> > Programs should switch from one to other according to needs.
> > For example, assume a sequence s  s = {}. Then, s &= 1. This can
> > be a byte (or bit) type. If then s &= 65, it remains byte. If then
> > s &= 3456, it should switch to word (the entire sequence). If then
> > s[1] = 12345678, it should switch to the current Euphoria integer type.
> > If then s[2] = 89.876, maybe the current scheme could be maintained
> > (AFAIK, only this element becomes floating point, and the rest remain
> > integer), or else the entire sequence switches to floating.
> 
> You've just described exactly the way APL does things.
> The problem with having n internal data types, is that you
> have to handle n-squared cases for every binary operation
> in the interpreter (or translator). This would be slow, and would
<snip>

new topic     » topic index » view message » categorize

2. Re: Robert Craig... One Wish Please

I'd like to see this too. For security reasons, the emergerency routine
could be aborted if it tries to access routine/variable that caused the bug.
Its funny when OS looses fonts and bitmaps because of resource leaks.
Without pictures and texts doesn't remain much of GUI...

    Martin


----- Original Message ----- 
From: "jordah ferguson" <jorfergie03 at yahoo.com>
To: "EUforum" <EUforum at topica.com>
Subject: Robert Craig... One Wish Please


> Hi Robert,
> 
> I have only one wish i would like added to exw. The ability to call a 
> routine at crash time or in case of a windows exception, similar to what 
> Matt lewis has done but built into the Euphoria interpreter/translator. 
> 
>      This is very handy when cleaning up GDI resources and Memory 
> allocations made using API calls rather than EU Calls. Generally, this 
> would help us clean-up and avoid reboots due to resource leaks.
> 
> How about that? WIN32 programmers back me up
> 
> jordah ferguson

new topic     » goto parent     » topic index » view message » categorize

3. Re: Robert Craig... One Wish Please

I've been asking for a crash_routine() for years.

Mike Sabal

>>> jorfergie03 at yahoo.com 07/30/02 12:49PM >>>

Hi Robert,

I have only one wish i would like added to exw. The ability to call a 
routine at crash time or in case of a windows exception, similar to
what 
Matt lewis has done but built into the Euphoria interpreter/translator.


     This is very handy when cleaning up GDI resources and Memory 
allocations made using API calls rather than EU Calls. Generally, this

would help us clean-up and avoid reboots due to resource leaks.

How about that? WIN32 programmers back me up

jordah ferguson

new topic     » goto parent     » topic index » view message » categorize

4. Re: Robert Craig... One Wish Please

Jordah Ferguson writes:
> I have only one wish i would like added to exw. The ability to call a
> routine at crash time ...

A global exception handler has been on my list for a long time,
at least in principle. It wouldn't be hard to implement,
but it raises some issues that have to be examined carefully,
for example:

   - It would be almost useless in code translated to C, since
     there are very few run-time error checks. It would increase the
     chances that a program could not be translated properly.

   - It might make certain optimizations more difficult, since
     you couldn't be sure at compile-time that a series of
     statements would always be executed in a predictable order.
     If I wanted to free the value of a global variable early, that might
     be a mistake, since an exception might happen, causing
     a sudden jump to a routine that uses that variable, etc.

   - People might start to "abuse" the feature, using it for normal
     processing, not just exceptions, especially when some clever
     person reports how he speeded up his loop by 5%, by removing his
     test for an out-of-bounds subscript, and relying instead on the
     exception handler.

   - It might preclude doing an eventual full treatment of
     exceptions like C++ and other languages, where
     each block of statements can have its own handler.

   - There are issues, such as: Do we allow the exception handler to return?
     Do we provide the exception handler with a standardized error code
     so it will know what happened? etc.

   - If you are mainly interested in freeing resources,
     you should know that Euphoria flushes your files and closes them,
     frees .dll's, and all the memory that you allocated
     via allocate() is freed as well.

   - If you mainly just want to apologize to your user and explain
     what to do, you can do that with crash_message().

I had an example a while back where I might have benefited from this.
I had a FreeBSD Euphoria background process running
24 hours a day and I thought it would be very useful if
it could send me an email if a Euphoria exception occurred.
Eventually I made it a "cron" job, started hourly, and I found
that cron itself sends me an e-mail if any error messages
occur when running a program. So the problem was solved.

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view message » categorize

5. Re: Robert Craig... One Wish Please

>From Robert Craig:
>A global exception handler has been on my list for a long time,
>at least in principle. It wouldn't be hard to implement,
>but it raises some issues that have to be examined carefully,
>
>    - It might preclude doing an eventual full treatment of
>      exceptions like C++ and other languages, where
>      each block of statements can have its own handler.

Ok, so a global exception handler is not difficult. Can you comment on the 
difficulty of implementing full treatment of exceptions?

And will it have 'proper' try/catch syntax, rather than through a procedural 
interface? I would think the first is easier to understand.
i.e.

try <exception>
    --some code
    --exception_causing code
    --some more code
catch <exception>
    --deal with it.
end try

OR
==

procedure catch()
    --deal with it.
end procedure

set_try("<exception>", routine_id("catch"))
--some code
--exception_causing code
--some more code
end_try("<exception>")


Also, if we could define exceptions, it would be nice... :P
=====================================================
.______<-------------------\__
/ _____<--------------------__|===
||_    <-------------------/
\__| Mr Trick

new topic     » goto parent     » topic index » view message » categorize

6. Re: Robert Craig... One Wish Please

Responses are below Rob's comments:

>>> rds at RapidEuphoria.com 07/30/02 11:49PM >>>
   - People might start to "abuse" the feature, 
This is true, but namespaces have potential for abuse too.  Unlike
goto, which is a stylistic enhancement, a crash_routine has highly
functional value.

   - There are issues, such as: Do we allow the exception handler to
return?
     Do we provide the exception handler with a standardized error
code
     so it will know what happened? etc.
The issue is really whether we trap the error before it occurs with
hundreds of lines of error-checking code, or do we trap it after it
occurs with hundreds of lines of error-handling code?  The cleaner
method is to trap the error before it occurs.  However, most programmers
will miss potential problems when designing.  There needs to be a method
of logging these bugs and allowing the user to continue working if at
all possible.  For example, a common bug is reading past the end of a
sequence or writing past the end of a sequence.  The crash_routine is
called with the standard code for an invalid sequence index as well as
the routine name (or line number) in which the error occurred.  The
routine opens for append a buglog, records the error, and closes the
file.  If the programmer is aware of this intermittent error, and can
simply increase the size of the sequence and return, the user can
happily continue his/her work until the true bug can be found.  If the
programmer cannot tell what sequence needs to be lengthened, he/she can,
still in the crash_routine, analyze the current record being entered (or
whatever other work is currently in progress) for data integrity and
save the record before the file gets closed.  Also a message_box can be
displayed, as opposed to the console-based crash_message.  This is the
real benefit to having a crash_routine, and these are things that cannot
be managed by existing Euphoria routines.

Michael J. Sabal

new topic     » goto parent     » topic index » view message » categorize

7. Re: Robert Craig... One Wish Please

-------Phoenix-Boundary-07081998-

You wrote on 7/30/02 8:42:27 PM:

>
>Ok, so a global exception handler is not difficult. Can you comment on the 
>difficulty of implementing full treatment of exceptions=3F
>
>And will it have 'proper' try/catch syntax, rather than through a 
>procedural interface=3F I would think the first is easier to understand.
>i.e.
>
>try <exception>
>    --some code
>    --exception_causing code
>    --some more code
>catch <exception>
>    --deal with it.
>end try
>
>OR
>=3D=3D
>
>procedure catch()
>    --deal with it.
>end procedure
>
>set_try("<exception>", routine_id("catch"))
>--some code
>--exception_causing code
>--some more code
>end_try("<exception>")
>

Bliss has throw-catch exceptions.

The throw statement searches the current run-time stack
for a procedure that has a catch. If found, control
is passed to it, and a variable is set to hold the
interesting information (id, msg, etc.). If no catch
is found, it is a fatal runtime error.

As a result of following this thread, I am 'finishing
off' the implementation by adding:

1) A variable can hold the routine id of a function
   to be called when an uncaught exception occurs.

2) Internal run-time errors generate exceptions (throw).

Does this meet the needs=3F

There is no 'try' 
No provision is made for returning from the throw.
   ( Isn't it true that when an array out of bounds
   error occurs the proper course is to retry a
   block of code, rather than a single instruction=3F)

An example:
   procedure foo (integer x)
      if x =3D 0 then
         throw ({202, "Argument cannot be 0"})
      end if
      ...
   end procedure

   procedure zot (integer cnt)
      ...
      foo (cnt)
      ...
      return
   catch
      if THROWN[1] =3D 202 then
         =3F"Oops -- cnt was zero!"
         return
      else
         throw()    -- rethrow the exception
      end if
   end procedure
  


Karl Bochert


-------Phoenix-Boundary-07081998---

new topic     » goto parent     » topic index » view message » categorize

8. Re: Robert Craig... One Wish Please

At 10:29 31/07/02 -0400, you wrote:
<snip>
>The issue is really whether we trap the error before it occurs with
>hundreds of lines of error-checking code, or do we trap it after it
>occurs with hundreds of lines of error-handling code?  The cleaner
>method is to trap the error before it occurs.
<snip>

I totally agree that is the cleaner approach.

I generally write short programs (less that 500 lines and many much
shorter) for my purposes (I'm from a system admin background) but even so
I'd say between 30 percent and even 60 percent of the lines of code I write
are some form of error checking, error reporting and, if possible, error
correction.

If you know a condition might exist that could cause future program flow to
fail then check for it, if it exists then try and correct it and if
"normal" processing cannot continue then raise an alert and either back off
(if in a batch/unattended environment) or ask the user (if in an
interactive environment) for an opinion on how to proceed.

Of course you don't know what all the possible errors could be.  For medium
and larger sized programs it is impossible (humanly) to predict all
combinations of logic flow so unexpected errors might and do occur.  In my
mind (yes it's a small place but the advantage is I know my way around smile
it is best to let the system tell you you've made a mistake.  You work out
what went wrong, how to handle this condition, amend your code and retest
(but see my final comment!).

If you rely on an error handling routine to patch things up and keep things
going then you have hugely increased the complexity of your code.  If you
look at code you have to think in the back of you mind "well at this stage
the code looks like it has done this with global variable X but at certain
times the crash recovery routine may have changed the value under the feet
of this routine".  Hmmm.  I can see tricky bugs lurking.

And another thing: what happens if the error handling routine itself
generates an error!?

Finally: I know that everytime I travel by plane many many lines of code
are flying it (for some of the time at least).  I wonder if the language
they used has "error handling routines"?  Remember that the programmer(s)
are not on the plane with you.

Regards,

Andy Cranston.

new topic     » goto parent     » topic index » view message » categorize

9. Re: Robert Craig... One Wish Please

{{{ On Tue, 30 Jul 2002 23:49:31 -0400, Robert Craig <rds at RapidEuphoria.com> wrote:

A global exception handler has been on my list for a long time,
at least in principle. It wouldn't be hard to implement,
but it raises some issues that have to be examined carefully,

Agreed. I vote the program *WILL* terminate after the call is made. Basically, (state this) the _on_crash_ routine can be set & is cleared before the routine is called; if the programmer is daft enuf to reset it during the crash procedure *ALL BETS ARE OFF*

for example:

- It would be almost useless in code translated to C, since
there are very few run-time error checks. It would increase the
chances that a program could not be translated properly.

I vote: forget this; xlate to C is a speed/release issue anyways. I suspect we're all more concerned with alpha/beta issues.

btw, I'm not up to speed on this. are you saying that given checks such as index of -1 are no longer checked at all in a xlated to c pgm?


- It might make certain optimizations more difficult, since
you couldn't be sure at compile-time that a series of
statements would always be executed in a predictable order.

Erm? I would strongly recommend (if it helps) that such a routine can only exist at top-level; not in an include file; no local vars - & even no calling of other procedures/functions (again if it helps).

If I wanted to free the value of a global variable early, that might
be a mistake, since an exception might happen, causing
a sudden jump to a routine that uses that variable, etc.

Erm again, I wouldn't expect either a) more than one fatal error trapping routine, or b) it to have *ANY* access other than to global variables - it's a programming (/er) issue, again. So it would/could only access stuff your standard top-to-bottom interpreter wouldn't dare release yet.


- People might start to "abuse" the feature, using it for normal
processing, not just exceptions, especially when some clever
person reports how he speeded up his loop by 5%, by removing his
test for an out-of-bounds subscript, and relying instead on the
exception handler.

Not at all what I want. I want the program to be able to save some stuff (globals), simple message perhaps, crap out & die as usual. Re-starting the program (eg a long edit) then offers the user a choice of restoring to file-on-disk or applying changes to some workable point (again, up to the programmer to figure that beast out)


- It might preclude doing an eventual full treatment of
exceptions like C and other languages, where > each block of statements can have its own handler.

I wholly, wholly, completely and utterly disagree; this is *NOT* exception handling; this is crap out and die handling. A different beast altogether.


- There are issues, such as: Do we allow the exception handler to return?

  • NO*

Do we provide the exception handler with a standardized error code
so it will know what happened? etc.

When possible, but largely, again, this is a programmer issue; It's *much* more important for an app to know which bit it was doing rather than a "divide by zero" just happened, as you all know.


- If you are mainly interested in freeing resources,
you should know that Euphoria flushes your files and closes them,
frees .dll's, and all the memory that you allocated
via allocate() is freed as well.

I trust you wholly in that respect.

<snip>

Rob, you're in alpha mode for 2.4 right now yeah? Live a little Stamp your foot down on some sensible limitations. Please don't use the word "exception"; it only confuses. Try fatal error instead. (or crap out and die handling!-) And yank it if it goes pear shaped.

Pete

new topic     » goto parent     » topic index » view message » categorize

10. Re: Robert Craig... One Wish Please

Ok,
Q:Why do we want error handling?

A:To stop the entire program crashing down on us when an intermittent or not 
easily reproducible error brings the entire program crashing down. The sort 
of error that can't be easily solved by checking for a
-1. Subscript errors come to mind.

I would like some way to return the program to normalcy once an error like 
this occurs, rather than just have the interpreter throw a hissy fit.

So, what I would like:
EG: I have is a sub-routine of a program that performs some incredibly 
complicated algorithm on a few complex sequences. *Occasionally*, it gets 
given a set that it can't process, so it currently crashes the whole 
program.
A nice solution would be to throw a subscript-error catch around the 
sub-routine, and put code in the catch that returns to the parent routine 
with an error flag, and a message. Thus, a user can get a MUCH more 
user-friendly dialog box saying "Sorry, an error has occurred" when this bug 
exhibits itself, then going back to the main window. ATM, you get a much 
less user-friendly blank screen, and the entire program crashes because of 
an error in a small part of it.

=====================================================
.______<-------------------\__
/ _____<--------------------__|===
||_    <-------------------/
\__| Mr Trick

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu