Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8012183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:15:05+00:00 2026-06-04T19:15:05+00:00

What is actually the difference between raising an exception in TCL via return -code

  • 0

What is actually the difference between raising an exception in TCL via return -code error ...and error ...? When would one be used instead of the other?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:15:06+00:00Added an answer on June 4, 2026 at 7:15 pm

    The error command produces an error right at the current point; it’s great for the cases where you’re throwing a problem due to a procedure’s internal state.
    The return -code error command makes the procedure it is placed in produce an error (as if the procedure was error); it’s great for the case where there’s a problem with the arguments passed to the procedure (i.e., the caller did something wrong).
    The difference really comes when you look at the stack trace.

    Here’s a (contrived!) example:

    proc getNumberFromFile {filename} {
        if {![file readable $filename]} {
            return -code error "could not read $filename"
        }
        set f [open $filename]
        set content [read $f]
        close $f
        if {![regexp -- {-?\d+} $content number]} {
            error "no number present in $filename"
        }
        return $number
    }
    
    catch {getNumberFromFile no.such.file}
    puts $::errorInfo
    #could not read no.such.file
    #    while executing
    #"getNumberFromFile no.such.file"
    
    catch {getNumberFromFile /dev/null}
    puts $::errorInfo
    #no number present in /dev/null
    #    while executing
    #"error "no number present in $filename""
    #    (procedure "getNumberFromFile" line 9)
    #    invoked from within
    #"getNumberFromFile /dev/null"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the difference between a Program Manager and Product Manager? Is there actually
If so, what is the difference between the two? Are there actually two separate
seam actually proxies every class for interception. is there a difference between proxied classes
I want to know the difference between ObservableCollection and BindingList because I've used both
Possible Duplicate: Difference between calling self.var vs var Edit : actually, i did not
what is actually difference between xmlhttprequest and $.ajax() i want to know which is
What is actually the difference between these two casts? SomeClass sc = (SomeClass)SomeObject; SomeClass
actually I want to know What is the difference between ./file name and ../file
I understand the difference between copy vs. deepcopy in the copy module. I've used
I need to be able to tell the difference between a read/write error, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.