1. ? 0/1 to throw an error?

I've seen this many times. Here's an example:

if bad = 1 then
    printf(1, "bad stuff here, cause a crash")
    ? 0/1
end if


How hard would it be to allow script writers the same type of error generation
that exists internally in Euphoria? For instance, the "bad stuff here, cause a
crash" message may print to stdout, but in a GUI app, they probably will not see
that message. They will be left with a ex.err file that says print_name() crashed
because it tried to divide by zero. They will then say, divide by zero? Huh? All
it was suppose to do is print a persons name.

Can we have an internal function that triggers a crash with a legitimate error
message?

if bad = 1 then
    crash("You gave an invalid index at which to search from")
end if


The reason this question has rose is from a few functions that Larry Miller
posted that I would like to include in the standard library:

http://www.openeuphoria.org/EUforum/m20164.html

--
Jeremy Cowgar
http://jeremy.cowgar.com

new topic     » topic index » view message » categorize

2. Re: ? 0/1 to throw an error?

Jeremy Cowgar wrote:
> 
> I've seen this many times. Here's an example:
> 
> }}}
<eucode>
> if bad = 1 then
>     printf(1, "bad stuff here, cause a crash")
>     ? 0/1
> end if
> </eucode>
{{{


This is sloppy programming, but useful since there is no other way to 
generate an ex.err file.  It would be better to simply change abort() to
spit out ex.err when it sees a negative integer, and flip the sign for the
exit code.

> Can we have an internal function that triggers a crash with a legitimate error
> message?

Euphoria already has crash_message.

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

3. Re: ? 0/1 to throw an error?

Michael J. Sabal wrote:
> 
> Jeremy Cowgar wrote:
> > 
> > I've seen this many times. Here's an example:
> > 
> > }}}
<eucode>
> > if bad = 1 then
> >     printf(1, "bad stuff here, cause a crash")
> >     ? 0/1
> > end if
> > </eucode>
{{{

> 
> This is sloppy programming, but useful since there is no other way to 
> generate an ex.err file.  It would be better to simply change abort() to
> spit out ex.err when it sees a negative integer, and flip the sign for the
> exit code.
> 
> > Can we have an internal function that triggers a crash with a legitimate
> > error
> > message?
> 
> Euphoria already has crash_message.

crash_message(), as I understand it, is not something to that the application
programmer can set to include contact information and/or any other information
they wish to have included in the crash log. For instance:

include machine.e
crash_message("App failed. Contact John Doe at 555-1212")
? find_from('a', "", 10)


This does not produce a ex.err file with anything about App failed. It simply
prints a message to the screen when a crash occurs.

Now, in the above example, the ex.err file looks like:

test.e:23
third argument of find_from() is out of bounds (10) 


Global & Local Variables

 /opt/euphoria/include/machine.e:
    mem = 135171344
    check_calls = 1


What I am suggesting is a way to let the programmer of a routine generate the
same type of message and cause a crash/ex.err dump as you can with internal
functions.

global function rfind_from(atom what, sequence in, integer start)
  if start_idx > length(0) then
    crash("third argument of rfind_from() is out of bounds(%d)", {start})
  end if
end function


abort does not do this. Abort exits the program with an error code.
crash_message does not do this. From what I can see, there is no way for an Eu
script to cause a crash and supply a crash message w/o reverting to a 0/1 type of
trick.

--
Jeremy Cowgar
http://jeremy.cowgar.com

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

4. Re: ? 0/1 to throw an error?

Jeremy Cowgar wrote:
> 
> abort does not do this. Abort exits the program with an error code.
> crash_message
> does not do this. From what I can see, there is no way for an Eu script to
> cause
> a crash and supply a crash message w/o reverting to a 0/1 type of trick.
> 

I guess I wasn't clear.  I was proposing that we amend abort to provide such
functionality:
1. If the parameter is a negative integer, generate an ex.err file.
2. If crash_message has been specified, make that the top line of the generated
ex.err, otherwise use a generic error along the lines of "Program aborted."

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

Search



Quick Links

User menu

Not signed in.

Misc Menu