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

What is supposed to happen if there is an error in a vim script?

Expand Messages
  • Rostyslaw Lewyckyj
    IF vim recognizes an error in a script, what does it do? Where are the rules for this detailed? Suppose that while editing file.foo, I initiate a script e.g.
    Message 1 of 8 , Mar 30, 2011
    • 0 Attachment
      IF vim recognizes an error in a script, what does it do?
      Where are the rules for this detailed?

      Suppose that while editing file.foo, I initiate a script
      e.g. :so myscript.vim
      and there is an error
      e.g. the script looks for a non existing pattern in file.foo
      After issuing its error message what is the expected action
      for the general case:
      1. The script is immediately terminated, returning to the
      invocation point?
      2. After possibly issuing an error message,
      the script continues trying to execute with its next command.
      In this case as if the search for the pattern had not failed?

      Are these kinds of exception rules spelled out explicitly
      anywhere in the available documentation?
      Not just mentioned in passing by an example!

      In my simple test case, it appears that 2. is the rule.
      But of course I'm just seemingly poking a black box.
      --
      Rostyk

      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Christian Brabandt
      ... Yes, in general, rule 2 applies. But when writing your script, you can define otherwise, using e.g. try/catch/finally or the abort keyword when defining a
      Message 2 of 8 , Mar 31, 2011
      • 0 Attachment
        On Thu, March 31, 2011 8:38 am, Rostyslaw Lewyckyj wrote:
        > IF vim recognizes an error in a script, what does it do?
        > Where are the rules for this detailed?
        >
        > Suppose that while editing file.foo, I initiate a script
        > e.g. :so myscript.vim
        > and there is an error
        > e.g. the script looks for a non existing pattern in file.foo
        > After issuing its error message what is the expected action
        > for the general case:
        > 1. The script is immediately terminated, returning to the
        > invocation point?
        > 2. After possibly issuing an error message,
        > the script continues trying to execute with its next command.
        > In this case as if the search for the pattern had not failed?
        >
        > Are these kinds of exception rules spelled out explicitly
        > anywhere in the available documentation?
        > Not just mentioned in passing by an example!
        >
        > In my simple test case, it appears that 2. is the rule.
        > But of course I'm just seemingly poking a black box.

        Yes, in general, rule 2 applies. But when writing your script,
        you can define otherwise, using e.g. try/catch/finally or the abort
        keyword when defining a function.

        regards,
        Christian

        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • Ben Schmidt
        ... Note that mappings abort on error, though. I think other commands like @ might, too. Since both these can actually run scripts, one way or another, it
        Message 3 of 8 , Mar 31, 2011
        • 0 Attachment
          On 31/03/11 6:25 PM, Christian Brabandt wrote:
          > On Thu, March 31, 2011 8:38 am, Rostyslaw Lewyckyj wrote:
          >> IF vim recognizes an error in a script, what does it do?
          >> Where are the rules for this detailed?
          >>
          >> Suppose that while editing file.foo, I initiate a script
          >> e.g. :so myscript.vim
          >> and there is an error
          >> e.g. the script looks for a non existing pattern in file.foo
          >> After issuing its error message what is the expected action
          >> for the general case:
          >> 1. The script is immediately terminated, returning to the
          >> invocation point?
          >> 2. After possibly issuing an error message,
          >> the script continues trying to execute with its next command.
          >> In this case as if the search for the pattern had not failed?
          >>
          >> Are these kinds of exception rules spelled out explicitly
          >> anywhere in the available documentation?
          >> Not just mentioned in passing by an example!
          >>
          >> In my simple test case, it appears that 2. is the rule.
          >> But of course I'm just seemingly poking a black box.
          >
          > Yes, in general, rule 2 applies. But when writing your script,
          > you can define otherwise, using e.g. try/catch/finally or the abort
          > keyword when defining a function.

          Note that mappings abort on error, though. I think other commands like @ might,
          too. Since both these can actually run scripts, one way or another, it somewhat
          depends in what context your script is running how errors are handled. To be sure
          how things will work, use :try.

          Ben.


          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Christian Brabandt
          ... True. Didn t think about mappings. regards, Christian -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the
          Message 4 of 8 , Mar 31, 2011
          • 0 Attachment
            On Thu, March 31, 2011 9:52 am, Ben Schmidt wrote:
            > Note that mappings abort on error, though. I think other commands like @
            > might,
            > too. Since both these can actually run scripts, one way or another, it
            > somewhat
            > depends in what context your script is running how errors are handled. To
            > be sure
            > how things will work, use :try.

            True. Didn't think about mappings.

            regards,
            Christian

            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • Andy Wokula
            ... Normally, a script is sourced to the end, even if errors occur. This is the same in all (also older) Vim versions. But if :source is executed within a
            Message 5 of 8 , Mar 31, 2011
            • 0 Attachment
              Am 31.03.2011 08:38, schrieb Rostyslaw Lewyckyj:
              > IF vim recognizes an error in a script, what does it do?
              > Where are the rules for this detailed?
              >
              > Suppose that while editing file.foo, I initiate a script
              > e.g. :so myscript.vim
              > and there is an error
              > e.g. the script looks for a non existing pattern in file.foo
              > After issuing its error message what is the expected action
              > for the general case:
              > 1. The script is immediately terminated, returning to the
              > invocation point?
              > 2. After possibly issuing an error message,
              > the script continues trying to execute with its next command.
              > In this case as if the search for the pattern had not failed?
              >
              > Are these kinds of exception rules spelled out explicitly
              > anywhere in the available documentation?
              > Not just mentioned in passing by an example!
              >
              > In my simple test case, it appears that 2. is the rule.
              > But of course I'm just seemingly poking a black box.

              :h except-compat

              Normally, a script is sourced to the end, even if errors occur. This is
              the same in all (also older) Vim versions.

              But if :source is executed within a :try-block, sourcing will stop on
              the first error.
              try
              so script.vim
              endtry

              If you want to still source to the end, you have to use :sil! to
              surpress errors:
              try
              :sil! so script.vim
              endtry

              What you can't have is: execute :so within a :try-block and still see
              all error messages (not only the first).

              --
              Andy

              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            • Rostyslaw Lewyckyj
              ... All very good hints and commets, thank you messieurs: Brabant, Schmidt, and Wokula. However none of you answered, ... Or is this an impossible task, since
              Message 6 of 8 , Mar 31, 2011
              • 0 Attachment
                Andy Wokula wrote:
                > Am 31.03.2011 08:38, schrieb Rostyslaw Lewyckyj:
                >> IF vim recognizes an error in a script, what does it do?
                >> Where are the rules for this detailed?
                >>
                >> Suppose that while editing file.foo, I initiate a script
                >> e.g. :so myscript.vim
                >> and there is an error
                >> e.g. the script looks for a non existing pattern in file.foo
                >> After issuing its error message what is the expected action
                >> for the general case:
                >> 1. The script is immediately terminated, returning to the
                >> invocation point?
                >> 2. After possibly issuing an error message,
                >> the script continues trying to execute with its next command.
                >> In this case as if the search for the pattern had not failed?
                >>
                >> Are these kinds of exception rules spelled out explicitly
                >> anywhere in the available documentation?
                >> Not just mentioned in passing by an example!
                >>
                >> In my simple test case, it appears that 2. is the rule.
                >> But of course I'm just seemingly poking a black box.
                >
                > :h except-compat
                >
                > Normally, a script is sourced to the end, even if errors occur. This is
                > the same in all (also older) Vim versions.
                >
                > But if :source is executed within a :try-block, sourcing will stop on
                > the first error.
                > try
                > so script.vim
                > endtry
                >
                > If you want to still source to the end, you have to use :sil! to
                > surpress errors:
                > try
                > :sil! so script.vim
                > endtry
                >
                > What you can't have is: execute :so within a :try-block and still see
                > all error messages (not only the first).
                >
                All very good hints and commets, thank you messieurs: Brabant, Schmidt,
                and Wokula.

                However none of you answered,
                >> Are these kinds of exception rules spelled out explicitly
                >> anywhere in the available documentation?
                >> Not just mentioned in passing by an example!

                >> Where are the rules for this detailed?

                Or is this an impossible task, since the rules of vim
                are not regular, but an ad hoc collection?
                (like French grammar. :-) )

                --
                Rostyk

                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php
              • howard Schwartz
                ... Actually the documentation does describe, in detail, the rules for handling errors, exceptions, and interrupts -- if the author of a script encloses it in
                Message 7 of 8 , Mar 31, 2011
                • 0 Attachment
                  > However none of you answered,
                  > anywhere in the available documentation?
                  > Not just mentioned in passing by an example!

                  > Where are the rules for this detailed?

                  Actually the documentation does describe, in detail, the rules for handling
                  errors, exceptions, and interrupts -- if the author of a script encloses it in
                  a ``try'' block. You can find these explanations in the document eval.txt in
                  Section 8 ``Exception Handling''. You can also use help commands to locate
                  descriptionfor the ``catch'' ``throw'' and ``finally'' commands within
                  ``try'' and ``endtry'' blocks.

                  I had to deal with this recently myself when I wrote a few scripts,.
                  Frankly, I found these rules unnecessarily complex and, well, arcane compared
                  to error handling in other script languages (e.g., unix shells).

                  Vim provides a set of rules for the Author of a script to deal with errors,
                  should he or she choose to do so. However, if the author does not use the
                  ``try'' mechanism - I fear errors are handled -well - however the developers
                  happened to handle each particular error. Generally, error messages are
                  displayed and some action may or may not be taken.

                  --
                  You received this message from the "vim_use" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php
                • Ben Schmidt
                  ... French grammar is pretty regular compared to some languages! ;-) I think the answer is that because error checking depends on the context, it is documented
                  Message 8 of 8 , Apr 1 4:00 AM
                  • 0 Attachment
                    > However none of you answered,
                    > >> Are these kinds of exception rules spelled out explicitly
                    > >> anywhere in the available documentation?
                    > >> Not just mentioned in passing by an example!
                    >
                    > >> Where are the rules for this detailed?
                    >
                    > Or is this an impossible task, since the rules of vim
                    > are not regular, but an ad hoc collection?
                    > (like French grammar. :-) )

                    French grammar is pretty regular compared to some languages! ;-)

                    I think the answer is that because error checking depends on the
                    context, it is documented at commands which change the error handling,
                    not as a set of overarching rules. So you will find details about error
                    handling while mappings are running somewhere near the :map command, and
                    how it works within :try blocks at the :try command, and how it works
                    while executing :global at that command, somewhere near :function the
                    abort modifier is explained, etc..

                    I guess the overarching rule, which I don't know if it's documented
                    anywhere, is that the way errors are handled depends on the 'enclosing
                    context' or something like that.

                    And Vim scripts, if just sourced, work just like running the commands
                    one after the other at the commandline, i.e. the next command is simply
                    typed in and executed regardless of the errors of the previous one. I
                    think that is in the docs somewhere, but no idea where....

                    So, yes, I guess in a sense that's a "the rules are not regular, but
                    they ARE documented (all over the place)."

                    Does that come close to answering your question?

                    Ben.



                    --
                    You received this message from the "vim_use" maillist.
                    Do not top-post! Type your reply below the text you are replying to.
                    For more information, visit http://www.vim.org/maillist.php
                  Your message has been successfully submitted and would be delivered to recipients shortly.