RE: [Windows] Associate file extensions with a program

new topic     » topic index » view thread      » older message » newer message

Matt Lewis wrote:
> 
> 
> posted by: Matt Lewis <matthewwalkerlewis at yahoo.com>
> 
> Pete Lomax wrote:
> > 
> > Juergen Luethje wrote:
> > 
> > > I can see that implementation #1 is not a good idea, but what about
> > > implementation #2?
> >
> > If there is an error in proc1, such as FileDoesNotExist, then it would
> > not help matters to replace this with ErrorWritingToFile in proc2.
> > 
> > In fact, wouldn't most error conditions tend to daisy-chain?
> 
> Yes.  It's important to allow for errors to propagate back up through
> the call chain.  I've done this a couple of different ways in EuSQL and
> in matheval.  In EuSQL, all functions return a sequence on success, and 
> an integer on failure.  After pretty much every call from a library 
> routine to another, I check this condition, and simply return the error
> code.  There is also an extended error message that can be set, and that
> an application can request.
> 
> In matheval, I defined a separate type, called INVALID.  Each matheval
> type is smart enough to only operate on other types that it understands,
> so the INVALID type is simply passed back.  Part of the INVALID type is
> an error message.
> 
> Matt Lewis

What you want is error trapping and exception handling.

I've written a library to deal with this..
It's not perfect, because we can't bail out of the call stack, but
otherwise, it's a good solution for error trapping.
Note also, that error trapping puts the sanity tests into the routines
that are actually making the errors. That is how it should be.
Error trapping also keeps the routine's result unambiguous.

here is a psuedo-example...
------------------------------------
allow_error_trapping(OFF)
allow_pending_errors(OFF)

constant ERR_FOPEN = define_error(NULL)
function fopen(sequence name, sequence flags)
  integer fn
   if fn = -1 then
     throw_error(ERR_FOPEN,"Failed to open "&name&" with the flags:
\'"*flags&"\'\n")
   end if
   return fn
end function

-- now I can do stuff like this..
integer fn1,fn2,fn3,fn4,fn5
fn1 = fopen("foo1.txt","rb")
fn2 = fopen("foo2.txt","rb")
fn3 = fopen("foo3.txt","rb")
fn4 = fopen("foo4.txt","rb")
fn5 = fopen("foo5.txt","rb")
trap_error(ERR_FOPEN)
----------------------------------------
In that specific example, trap_error() is not even needed at all.

If allow_error_trapping() is OFF, allow_pending_errors() has no affect.

With allow_error_trapping(OFF), each error is thrown and called
immmediately. throw_error() acts like a regular error msg routine.
For example, if foo1.txt fails.. the error occurs immediately within
fopen()

With allow_error_trapping(ON), and allow_pending_errors(OFF), each error
is thrown, but is not called unless an error is already pending.
For example, if foo1.txt fails, and foo3.txt fails, the error will be
thrown for foo1.txt when the error for foo3.txt is discovered.

With allow_error_trapping(ON) and allow_pending_errors(ON), each error
is thrown, and only called via trap_error()
For example, if foo1.txt fails, and foo3.txt fails.
Eu will still process each fopen statement. When it reaches, and calls
trap_error(ERR_FOPEN), it checks for any pending errors, matching that
ERR_FOPEN, and calls the first occurance. (An error would be
instantiated for foo1.txt)

The library does much more than I have described. Such as the ability to
define custom error handlers for each error code, the ability to catch,
drop, fetch and intercept exceptions, and some other lower level error
routines.

I'll share it with anyone interested. I'm not going to post it, because
the code is written for my own libraries, and isn't compatible with the
official rds libraries. There also isn't any documentation. If there is
anyone interested, I can port it back for them, and whip up some docs.


Chris Bensler
Code is Alchemy

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu