Re: catch replacing useful errorInfo



On Aug 31, 7:04 am, Donald G Porter <d...@xxxxxxxx> wrote:
Donald G Porter <d...@xxxxxxxx> wrote:

Let's look at the corrected example again: ...
tom.rmadilo wrote:
I can't see how this differs from what I said...

OK, violent agreement then. :)


I hate to admit it, but yes!

Maybe it is easier to say it this way: if you catch an error, throw an
error. Maybe not 100% applicable, but all the examples on this thread
do exactly that. If you don't want to throw an error, figure out how
to avoid the need to catch one.

I can agree on all that as good general advice.

So now time for counter-examples! I don't want you to get the
impression that I don't violate my own advice, but this goes to more
or less supporting the point that using catch is difficult, in the
sense that you can't necessarily look at a chunk of code and determine
good/bad/okay.


In this example, the pattern is supplied by the user. Before accepting
it, it needs to be minimally tested. Does the regexp compile? If not
an error will be thrown. So I test compile it, using a catch. On
failure, I return a message to the client (actually the application
writer, not the end user) indicating failure, and it aborts the
script:
.....
pattern {
if {[catch {regexp $Restrictions(pattern) abc} errorMsg]} {
return -code error "failed pattern test on $tns $typeName
$errorMsg"
}
}
whitespace {
if {[lsearch -exact {preserve replace collapse}
$Restrictions(whitespace)] == -1} {
return -code error "whitespace must be one of preserve,
replace or collapse"
}
}
......

Second example uses catch to continue loading an application. Why?
Shouldn't the application abort on error? Actually the application is
a shared resource. If a buggy package is added to the system, should
all functionality be lost? Continued loading allows you to figure out
if the error is harmless:

proc ::tws::util::package::loadPackages { packageList } {

foreach package $packageList {

if {[catch {
procs $package
} err ]} {
global errorInfo
log Error $errorInfo [list PACKAGE "$package"]
}
}
.....

Third example allows silent failure of a documentation proc. Is this
good practice? Maybe not for finished code. But I'm not sure what
would lead to failure just yet. Since documentation is not the primary
function of the application, for now just catch the error. This type
of error reporting is for the application developer and isn't
triggered by any user input. It is also possible that repeated logging
of the error will do more harm than good. Difficult call:

while {1} {
# First check that we have a real web service
if {![<ws>namespace exists $tclNamespace]
|| [<ws>namespace isFrozen $tclNamespace]
} {
break
}
# Only document certain components
# Note: eventually get search list from the web service
if {[lsearch -exact {type element operation} $what] == -1} {
break
} else {
set what ${what}s
}

catch {::wsdl::doc::document doc $what $xmlAlias $name $docString}

break
}

In a 50k line application, those are the only uses of catch. Two of
them appear on the surface to violate the general rule of catch and
throw, but 50k lines follow the advice of figuring out how to avoid
catch in the first place.

.



Relevant Pages

  • Re: [opensuse] Only root can use scanner on SuSE 10.2
    ... what I did and "let it get autodetected and configured by YAST" ... Is there some other package on which all of this relies that everyone's assuming I have? ... but I can't find any such script or documentation in any of the three packages installed on the machine which have "sane" in the package name. ... Perhaps Mr. Meissner will elaborate on his advice. ...
    (SuSE)
  • Re: A non-zero exit code of 3221225478 was returned.
    ... If I send the same package to the same machine then it worked ... >> failure. ... >> for the program you are distributing. ...
    (microsoft.public.sms.swdist)
  • Re: Finding installed package files
    ... > you appear to want is a file that lists executables and documentation. ... contains links to the most important information about the installation. ... > doubt others could finesse the command. ... I do understand that rpm has many options that tell me about a package. ...
    (alt.os.linux.redhat)
  • Re: Multiple files in a .dtx
    ... a .ins file to extract additional files from a .dtx file (and how to ... I need the package to contain a .sty file and several ... It automatically adds a default preamble and postamble. ... The dtxtut and doctex documentation seems less than forthcoming about ...
    (comp.text.tex)
  • Re: Monitor individual tasks within a DTS package
    ... failure, rather than using multiple Failure constraints. ... > Personally I find this too much hassle, but if you set package logging on to ...
    (microsoft.public.sqlserver.dts)