[GRASS-dev] Re: gis.m crashes on zoom to map existing in more than one mapset

Glynn Clements glynn at gclements.plus.com
Fri Jan 5 08:42:11 EST 2007


Paul Kelly wrote:

> I am guessing that "catch" catches errors by seeing if anything is written 
> to stderr - if a warning is written to stderr will it incorrectly catch it 
> as an error?

"catch" catches exceptions thrown by Tcl. It isn't limited to I/O,
e.g.:

	% set foo [expr 1 / 0]
	divide by zero
	% catch {set foo [expr 1 / 0]} res
	1
	% puts $res
	divide by zero
	% catch {set foo [expr 10 / 2]} res
	0
	% puts $res
	5

Tcl's process-creation code throws an exception if anything is written
to stderr. For "exec", it's the exec call which throws the exception. 

For "open |...", the corresponding "close" will throw an exception
(the error won't have occurred at the point that open returns, which
will typically be soon after the fork(), possibly before the child has
even called execve()).

I'm not sure, but it's possible that reading from the pipe may also
throw an exception. In simple cases, the entire open/read/close loop
should be contained within a single catch; in more complex cases, each
individual function needs its own catch.

>I'm not sure, but merging stderr into stdout with the grocat 
> program will stop anything being written to stderr so will stop this. This 
> will work on Windows - in fact I wrote it specifically because the 
> previous way it was done (see my recent changes to 
> lib/gtcltk/gronsole.tcl) was Unix-specific - the grocat trick works on 
> Unix and Windows.

In this case, an alternative is to simply redirect stderr elsewhere,
e.g. to @stdout (may not work on Windows) or /dev/null (nul on
Windows).

> Then within the while loop I've used an if to check the return value of 
> regexp - there are only two possible values - 1 if it matches the line and 
> 0 if it doesn't. So it won't match the Warning line, will return 0, and 
> thus stops you trying to assign non-existent values to key and value.

In general, any Tcl code which attempts to parse program output needs
to silently ignore unexpected output, as stderr often has to be merged
with stdout due to Tcl's "writing to stderr == error" behaviour.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list