<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.harlamenkov.ru/index.php?action=history&amp;feed=atom&amp;title=EN%2Fdocumentation%2Fbasic_guide%2Ferror_handling</id>
	<title>EN/documentation/basic guide/error handling - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.harlamenkov.ru/index.php?action=history&amp;feed=atom&amp;title=EN%2Fdocumentation%2Fbasic_guide%2Ferror_handling"/>
	<link rel="alternate" type="text/html" href="https://wiki.harlamenkov.ru/index.php?title=EN/documentation/basic_guide/error_handling&amp;action=history"/>
	<updated>2026-11-11T13:54:47Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://wiki.harlamenkov.ru/index.php?title=EN/documentation/basic_guide/error_handling&amp;diff=15890&amp;oldid=prev</id>
		<title>Sancho: Created page with &quot;&lt;section begin=title /&gt;&lt;noinclude&gt;{{DISPLAYTITLE:&lt;/noinclude&gt;Error Handling&lt;noinclude&gt;}}&lt;/noinclude&gt;&lt;section end=title /&gt;{{BreadCrumbL10n}}  {{Documentation/BASICGuideTOC |ShowPr...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.harlamenkov.ru/index.php?title=EN/documentation/basic_guide/error_handling&amp;diff=15890&amp;oldid=prev"/>
		<updated>2011-09-01T15:36:20Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;section begin=title /&amp;gt;&amp;lt;noinclude&amp;gt;{{DISPLAYTITLE:&amp;lt;/noinclude&amp;gt;Error Handling&amp;lt;noinclude&amp;gt;}}&amp;lt;/noinclude&amp;gt;&amp;lt;section end=title /&amp;gt;{{BreadCrumbL10n}}  {{Documentation/BASICGuideTOC |ShowPr...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;section begin=title /&amp;gt;&amp;lt;noinclude&amp;gt;{{DISPLAYTITLE:&amp;lt;/noinclude&amp;gt;Error Handling&amp;lt;noinclude&amp;gt;}}&amp;lt;/noinclude&amp;gt;&amp;lt;section end=title /&amp;gt;{{BreadCrumbL10n}}&lt;br /&gt;
&lt;br /&gt;
{{Documentation/BASICGuideTOC&lt;br /&gt;
|ShowPrevNext=block&lt;br /&gt;
|ShowPrevPage=block&lt;br /&gt;
|PrevPage=EN/documentation/basic_guide/procedures_and_functions&lt;br /&gt;
|NextPage=EN/documentation/basic_guide/other_instructions&lt;br /&gt;
|lang=block&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
__NOTOC__&lt;br /&gt;
&lt;br /&gt;
Correct handling of error situations is one of the most time-consuming tasks of programming. {{OOo}} Basic provides a range of tools for simplifying error handling.&lt;br /&gt;
&lt;br /&gt;
== The &amp;lt;tt&amp;gt;On Error&amp;lt;/tt&amp;gt; Instruction ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;On Error&amp;lt;/tt&amp;gt; instruction is the key to any error handling:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Sub Test&lt;br /&gt;
  On Error Goto ErrorHandler&lt;br /&gt;
  ' ... undertake task during which an error may occur&lt;br /&gt;
  Exit Sub&lt;br /&gt;
  ErrorHandler: &lt;br /&gt;
    ' ... individual code for error handling&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;On Error Goto ErrorHandler&amp;lt;/tt&amp;gt; line defines how {{OOo}} Basic proceeds in the event of an error. The &amp;lt;tt&amp;gt;Goto ErrorHandler&amp;lt;/tt&amp;gt; ensures that {{OOo}} Basic exits the current program line and then executes the &amp;lt;tt&amp;gt;ErrorHandler:&amp;lt;/tt&amp;gt; code. &lt;br /&gt;
&lt;br /&gt;
== The &amp;lt;tt&amp;gt;Resume&amp;lt;/tt&amp;gt; Command ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;Resume Next&amp;lt;/tt&amp;gt; command continues the program from the line that follows where the error occurred in the program after the code in the error handler has been executed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
ErrorHandler:&lt;br /&gt;
  ' ... individual code for error handling&lt;br /&gt;
  Resume Next&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;tt&amp;gt;Resume Proceed&amp;lt;/tt&amp;gt; command to specify a jump point for continuing the program after error handling:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
ErrorHandler:&lt;br /&gt;
  ' ... individual code for error handling&lt;br /&gt;
  Resume Proceed&lt;br /&gt;
 &lt;br /&gt;
Proceed:&lt;br /&gt;
  ' ... the program continues here after the error&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The term Proceed is a label. It could be for example, A247. The syntax for label names is the same as for variable names.&lt;br /&gt;
 &lt;br /&gt;
To continue a program without an error message when an error occurs, use the following format: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Sub Test&lt;br /&gt;
  On Error Resume Next&lt;br /&gt;
  ' ... perform task during which an error may occur&lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use the &amp;lt;tt&amp;gt;On Error Resume Next&amp;lt;/tt&amp;gt; command with caution as its effect is global.&lt;br /&gt;
&lt;br /&gt;
== Queries Regarding Error Information ==&lt;br /&gt;
&lt;br /&gt;
In error handling, it is useful to have a description of the error and to know where and why the error occurred:&lt;br /&gt;
&lt;br /&gt;
* The &amp;lt;tt&amp;gt;Err&amp;lt;/tt&amp;gt; variable contains a number identifying the type of error that has occurred.&lt;br /&gt;
* The &amp;lt;tt&amp;gt;Error$&amp;lt;/tt&amp;gt; variable contains a description of the error.&lt;br /&gt;
* The &amp;lt;tt&amp;gt;Erl&amp;lt;/tt&amp;gt; variable contains the line number where the error occurred. &lt;br /&gt;
&lt;br /&gt;
The call&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
 MsgBox &amp;quot;Error &amp;quot; &amp;amp; Err &amp;amp; &amp;quot;: &amp;quot; &amp;amp; Error$ &amp;amp; &amp;quot; (line : &amp;quot; &amp;amp; Erl &amp;amp; &amp;quot;)&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
shows how the error information can be displayed in a message window. &lt;br /&gt;
&lt;br /&gt;
{{VBAnote|Whereas VBA summarizes the error messages in a global object called &amp;lt;tt&amp;gt;Err&amp;lt;/tt&amp;gt;, {{OOo}} Basic provides the &amp;lt;tt&amp;gt;Err,&amp;lt;/tt&amp;gt; &amp;lt;tt&amp;gt;Error$&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;Erl&amp;lt;/tt&amp;gt; variables.}}&lt;br /&gt;
&lt;br /&gt;
The status information remains valid until the program encounters a &amp;lt;tt&amp;gt;Resume&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;On Error&amp;lt;/tt&amp;gt; command, whereupon the information is reset. &lt;br /&gt;
&lt;br /&gt;
{{VBAnote|In VBA, the &amp;lt;tt&amp;gt;Err.Clear&amp;lt;/tt&amp;gt; method of the &amp;lt;tt&amp;gt;Err&amp;lt;/tt&amp;gt; object resets the error status after an error occurs. In {{OOo}} Basic, this is accomplished with the &amp;lt;tt&amp;gt;On Error&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;Resume&amp;lt;/tt&amp;gt; commands. }}&lt;br /&gt;
&lt;br /&gt;
== Tips for Structured Error Handling ==&lt;br /&gt;
&lt;br /&gt;
Both the definition command, &amp;lt;tt&amp;gt;On Error&amp;lt;/tt&amp;gt;, and the return command, &amp;lt;tt&amp;gt;Resume&amp;lt;/tt&amp;gt;, are variants of the &amp;lt;tt&amp;gt;Goto&amp;lt;/tt&amp;gt; construct.&lt;br /&gt;
&lt;br /&gt;
If you want to cleanly structure your code to prevent generating errors when you use this construct, you should not use jump commands without monitoring them.&lt;br /&gt;
&lt;br /&gt;
Care should be taken when you use the &amp;lt;tt&amp;gt;On Error Resume Next&amp;lt;/tt&amp;gt; command as this dismisses all open error messages.&lt;br /&gt;
&lt;br /&gt;
The best solution is to use only one approach for error handling within a program - keep error handling separate from the actual program code and do not jump back to the original code after the error occurs.&lt;br /&gt;
&lt;br /&gt;
The following code is an example of an error handling procedure:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Sub Example&lt;br /&gt;
  ' Define error handler at the start of the function &lt;br /&gt;
  On Error Goto ErrorHandler   &lt;br /&gt;
    ' ... Here is the actual program code&lt;br /&gt;
  On Error Goto 0           ' Deactivate error handling&lt;br /&gt;
    ' End of regular program implementation&lt;br /&gt;
  Exit Sub&lt;br /&gt;
&lt;br /&gt;
 ' Start point of error handling&lt;br /&gt;
 ErrorHandler:                &lt;br /&gt;
   ' Check whether error was expected&lt;br /&gt;
    If Err = ExpectedErrorNo Then   &lt;br /&gt;
      ' ... Process error&lt;br /&gt;
    Else&lt;br /&gt;
      ' ... Warning of unexpected error&lt;br /&gt;
    End If&lt;br /&gt;
 On Error Goto 0            ' Deactivate error handling &lt;br /&gt;
End Sub&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This procedure begins with the definition of an error handler, followed by the actual program code. At the end of the program code, the error handling is deactivated by the &amp;lt;tt&amp;gt;On Error Goto 0&amp;lt;/tt&amp;gt; call and the procedure implementation is ended by the &amp;lt;tt&amp;gt;Exit Sub&amp;lt;/tt&amp;gt; command (not to be confused with &amp;lt;tt&amp;gt;End Sub&amp;lt;/tt&amp;gt;). &lt;br /&gt;
&lt;br /&gt;
The example first checks if the error number corresponds to the expected number (as stored in the imaginary &amp;lt;tt&amp;gt;ExpectedErrorNo&amp;lt;/tt&amp;gt; constant) and then handles the error accordingly. If another error occurs, the system outputs a warning. It is important to check the error number so that unanticipated errors can be detected.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;On Error Goto 0&amp;lt;/tt&amp;gt; call at the end of the code resets the status information of the error (the error code in the &amp;lt;tt&amp;gt;Err&amp;lt;/tt&amp;gt; system variables) so that an error occurring at a later date can be clearly recognized.&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
{{PDL1}}&lt;/div&gt;</summary>
		<author><name>Sancho</name></author>
		
	</entry>
</feed>