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

  • SEARCH
  • Home
  • 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 7909691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:33:01+00:00 2026-06-03T12:33:01+00:00

I try to capture lines with calculations in my text document and execute them.

  • 0

I try to capture lines with calculations in my text document
and execute them.

I use this in my function:

for i in range(startline,endline) 
let calculation = getline(i)  
...  
let out = eval(calculation)  
...  
endfor  

sometimes something goes wrong and I receive this message:

Error detected while processing function....  
Line ...  
E488: Trailing Characters   

Line .. is the line-nr in my function.
I would like to know also which calculation it concerns (which line in my text doc):

If Error detected = echo calculation

How can I check if there is an error message and echo the variable “calculation”?

  • 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-03T12:33:10+00:00Added an answer on June 3, 2026 at 12:33 pm

    There are two ways to handle script errors inside a function:

    The first is suppressing the error via :silent!. Two downsides: You have to manually check for success, and any normal output from the evaluated script is suppressed, too (unless you do contortions with :unsilent).

    let v:errmsg = ''
    silent! let out = eval(calculation)
    if v:errmsg != ''
        " error
    endif
    

    I would recommend the second way via try…catch, which avoids the issues with the output and having to explicitly check for an error:

    try
        let out = eval(calculation)
    catch /^Vim\%((\a\+)\)\=:E/
        " v:exception contains what is normally in v:errmsg, but with extra
        " exception source info prepended, which we cut away.
        let v:errmsg = printf("Line: %d\nCalculation: %s\nError: %s", i, calculation, substitute(v:exception, '^Vim\%((\a\+)\)\=:', '', ''))
        echohl ErrorMsg
        echomsg v:errmsg
        echohl None
    endtry
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i try to capture this key : alt+arrow down, alt+arrow up. First, i capture
i try using window.attachEvent (or addEventListener) to capture js errors my callback function gets
I'm getting this error at runtime when I try to use getClass.getPackage().getImplementationVersion(), in my
I'm making an application in Jython where I try to capture mouse events on
I have been tweaking a regular expression over several days to try to capture,
We have used Google form, Wufoo form to try to securely capture the info
I try to parse articles from wikipedia. I use the *page-articles.xml file, where they
I am trying to let a user capture an image and add it onto
I try to capture events on a subclassed MKOverlayView with a UIGestureRecognizer. However the
I can capture data from serial device via pyserial, at this time I can

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.