Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

catch

Status
Not open for further replies.

bebig

Technical User
Oct 21, 2004
111
US
hi,
I am trying "catch" command.
========================================
set readFileInput [open testA1.txt" "r"]

If the file does not exist, the errors occur. how to start catch statment??

this is what I am thinking.

set retval [catch $readFileInput]

if {$retval != 1} {
puts "An error occurred"
}

Thank you in advance
 
No, you are thinking one step too late.
try-
Code:
proc openFile {name {opt "r"}} {

          if {[catch {set fd [open $name $opt]} err]} {
              puts $"error: $err"
              return -1
          }
          return $fd
}

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top