Loading ...
Sorry, an error occurred while loading the content.

Re: using v:errmsg for checking error condition considered harmful

Expand Messages
  • Bram Moolenaar
    ... The /E426/ could be removed to also avoid errors such as tags file not found . -- hundred-and-one symptoms of being an internet addict: 63. You start
    Message 1 of 2 , Apr 29, 2004
    • 0 Attachment
      Vassily Ragosin wrote:

      > windows.txt quotes the following example:
      >
      > : " Try displaying a matching tag for the word under the cursor
      > : let v:errmsg = ""
      > : exe "silent! ptag " . w
      > : if v:errmsg =~ "tag not found"
      > : return
      > : endif
      >
      > when it should do
      >
      > : " Try displaying a matching tag for the word under the cursor
      > : let v:errmsg = ""
      > : exe "silent! ptag " . w
      > : if v:errmsg !~ ""
      > : return
      > : endif
      >
      > reason is that such a check does not take into account the possibility of
      > using a localized error message and won't work in such environment.
      >
      > Using v:errmsg to make a check whether certain error condition has occurred
      > should be considered harmful. Perhaps, some other changes due.

      It's even better to use try/endtry:

      : " Try displaying a matching tag for the word under the cursor
      : try
      : exe "ptag " . w
      : catch /E426/
      : return
      : endtry

      The "/E426/" could be removed to also avoid errors such as "tags file
      not found".

      --
      hundred-and-one symptoms of being an internet addict:
      63. You start using smileys in your snail mail.

      /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
      /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
      \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
      \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///
    Your message has been successfully submitted and would be delivered to recipients shortly.