From: <ec...@we...> - 2006-11-03 08:17:52
|
> Yes, but the rethrowing of an error could take place very far from > where it originally happened. With something like > http://wiki.tcl.tk/using, you don't get the requested chance to debug > errors that happen within the [using], since that command catches and > rethrows errors. Just an endorsement to this... You wouldn't implement a procedure this way in practice. Why? Because you can't debug it with *any* method - it is useless here to catch the error just to rethrow it at a different place. The only good reason to catch an error and rethrow it is to do some special processing *immediately* - e.g. - close resources - do some logging mumble. - etc... In the case of [using], it would look like this: proc using {varName chan script} { upvar 1 $varName var set var $chan set rc [catch { uplevel 1 $script } result] # log any error and proceed if {$rc} { puts "Yipieee, an error: $result" } catch { close $chan } return -code $rc } or like this: proc using {varName chan script} { upvar 1 $varName var set var $chan set rc [catch { uplevel 1 $script } result] # step out on error. Close the channel before if {$rc} { catch {close $chan} error "Yippieee, there was an error: $result" } catch { close $chan } return $result } In the first case, you don't want to debug anything yet - you consider that it is enough to have it logged. In the second case, you get an error immediately, which can be trapped and debugged. BTW, the new [info frame] command (TIP #280) is very helpful here. Eckhard PS: <cite src="http://lambda-the-ultimate.org/node/1544#comment-18176"> People have an unfortunate tendency to ignore these basic conveniences and focus on hypothetical software-engineering mumbo-jumbo scenarios. "Oh my, what if Luke installed an exception handler that ROT13 encoded every string on the heap, then how would Jane debug her programs?" This is not the way to illumination. </cite> _____________________________________________________________________ Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! http://smartsurfer.web.de/?mc=100071&distributionid=000000000066 |