Difference between revisions of "Category:Error Handling"
Barrymavin (Talk | contribs) (→Using DEBUGOUT) |
Barrymavin (Talk | contribs) (→JavaScript) |
||
(39 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | |||
{{DISPLAYTITLE:Error Handling and Debugging}} | {{DISPLAYTITLE:Error Handling and Debugging}} | ||
Debugging is one of the most important skills for a developer. Software development is all about writing code, making mistakes, and fixing them. | Debugging is one of the most important skills for a developer. Software development is all about writing code, making mistakes, and fixing them. | ||
Line 7: | Line 6: | ||
Lianja App Builder is quite unique in that as you develop an App you are working directly on live data running live dynamically compiled code. This development paradigm encourages agile development and to assist you further, Lianja App Builder provides some very powerful graphical debugging tools for you to use. | Lianja App Builder is quite unique in that as you develop an App you are working directly on live data running live dynamically compiled code. This development paradigm encourages agile development and to assist you further, Lianja App Builder provides some very powerful graphical debugging tools for you to use. | ||
− | == | + | ==Troubleshooter== |
− | + | The Troubleshooter provides a tabbed interface bringing together debugging, tracing and performance metrics to assist you in testing and tuning your Apps. | |
− | + | [[{{ns:file}}:troubleshooter.png|800px|left|border|link={{filepath:troubleshooter.png}}|Troubleshooter]] | |
+ | <br clear=all> | ||
− | + | ===Desktop Tab=== | |
+ | The Desktop Tab contains the following: | ||
− | + | {| class="wikitable" width="100%" | |
+ | !width="25%"|Tab | ||
+ | !width="75%"|Description | ||
+ | |- | ||
+ | |valign="top"|[[Troubleshooter Debugger Tab|Debugger]] | ||
+ | |valign="top"|Contains the LianjaScript Debugger. | ||
+ | |- | ||
+ | |valign="top"|[[Troubleshooter Python Debugger Tab|Python Debugger]] | ||
+ | |valign="top"|Contains the Python Debugger. | ||
+ | |- | ||
+ | |valign="top"|[[Troubleshooter JavaScript Debugger Tab|JavaScript Debugger]] | ||
+ | |valign="top"|Contains the JavaScript Debugger. | ||
+ | |- | ||
+ | |valign="top"|[[Troubleshooter Error Viewer Tab|Error Viewer]] | ||
+ | |valign="top"|Contains error message output. | ||
+ | |- | ||
+ | |valign="top"|[[Troubleshooter Debugout Tab|Debugout]] | ||
+ | |valign="top"|Contains [[DEBUGOUT|debugout]] message output. | ||
+ | |- | ||
+ | |valign="top"|[[Troubleshooter Debug File Tab|Debug File]] | ||
+ | |valign="top"|Contains debug information in the event of an error. | ||
+ | |- | ||
+ | |valign="top"|[[Troubleshooter Trace File Tab|Trace File]] | ||
+ | |valign="top"|Contains debug tracing information. | ||
+ | |- | ||
+ | |valign="top"|[[Troubleshooter UIState Trace Tab|UIState Trace]] | ||
+ | |valign="top"|Contains tracing information about [[UI States|UI State]] transition operations. | ||
+ | |- | ||
+ | |valign="top"|[[Troubleshooter Performance Metrics Tab|Performance Metrics]] | ||
+ | |valign="top"|Contains tracing and performance metrics for internal operations and events to allow you to see how events are fired and handled in your code and help you in performance tuning. | ||
+ | |- | ||
+ | |valign="top"|[[Troubleshooter Profiler Metrics Tab|Profiler Metrics]] | ||
+ | |valign="top"|Contains [[LIST PROFILE|Profiler]] environment settings and data when a LianjaScript prg is profiled in the [[Apps Workspace]]. | ||
+ | |- | ||
+ | |} | ||
− | === | + | ===Server Tab=== |
+ | The Server Tab contains the following: | ||
− | + | {| class="wikitable" width="100%" | |
+ | !width="25%"|Tab | ||
+ | !width="75%"|Description | ||
+ | |- | ||
+ | |valign="top"|[[Troubleshooter Server Error Viewer Tab|Error Viewer]] | ||
+ | |valign="top"|Contains server error message output. | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | ==LianjaScript Debugging Commands== | ||
+ | |||
+ | ===debugout=== | ||
+ | With [[SET DEBUGOUT|set debugout]] on, the [[DEBUGOUT|debugout]] command can be used to log text messages to the debug.txt file in the Lianja debug sub-directory and displayed in the [[Troubleshooter Debugout Tab]]. The [[DEBUGOUT|debugout]] command is ignored if [[SET DEBUGOUT|set debugout]] is off. | ||
+ | |||
+ | <code lang="recital"> | ||
+ | // debugdoc.prg | ||
+ | set debugout on | ||
+ | debugout "about to open database" | ||
+ | open database southwind | ||
+ | debugout "about to open table" | ||
+ | use example | ||
+ | replace all available with limit - balance | ||
+ | debugout "after replace" | ||
+ | close databases | ||
+ | debugout "after close data" | ||
+ | set debugout off | ||
+ | // Following line will not be logged: | ||
+ | debugout "no need to log this" | ||
+ | // end | ||
+ | </code> | ||
+ | |||
+ | '''debug.txt''' contents: | ||
<pre> | <pre> | ||
− | + | Debugout called from DEBUGDOC at line 3: about to open database | |
+ | Debugout called from DEBUGDOC at line 5: about to open table | ||
+ | Debugout called from DEBUGDOC at line 8: after replace | ||
+ | Debugout called from DEBUGDOC at line 10: after close data | ||
</pre> | </pre> | ||
− | + | ===set debug=== | |
+ | With [[SET DEBUG|set debug]] on, debugging and error information is logged to the debug text file in the lianja debug sub-directory and displayed in the [[Troubleshooter Debug File Tab]]. By default, [[SET DEBUG|set debug]] is off. The debugging information will contain a valuable insight into the internal code so when trying to track down a hard to locate bug [[SET DEBUG|set debug]] on may be your life saver. | ||
− | === | + | ===set debugtrace=== |
+ | With [[SET DEBUGTRACE|set debugtrace]] on, a trace of command execution is included in the debug text file output when [[SET DEBUG|set debug]] is on. By default, [[SET DEBUGTRACE|set debugtrace]] is off. | ||
− | == | + | ===set debugcompile=== |
+ | With [[SET DEBUGCOMPILE|set debugcompile]] on, the compiler includes debugging information in the compiled code file. This information is then included in the debug text file output when [[SET DEBUG|set debug]] is on. By default, [[SET DEBUGCOMPILE|set debugcompile]] is off. | ||
− | With SET | + | ===set errorlogging=== |
+ | With [[SET ERRORLOGGING|set errorlogging]] on, errors are logged to the debug text file. By default, [[SET ERRORLOGGING|set errorlogging]] is ON. | ||
− | == | + | ==Lianja System Object Methods== |
+ | The following cross platform and cross language Lianja system object text logging methods are available: | ||
− | === | + | {| class="wikitable" width=100% |
+ | !width="30%"|Method | ||
+ | !width="70%"|Description | ||
+ | |- | ||
+ | |valign="top"|[[Lianja_Methods#console|Lianja.console()]] | ||
+ | |valign="top"|Write the specified string to the console output window. | ||
+ | |- | ||
+ | |valign="top"|[[Lianja_Methods#log|Lianja.log()]] | ||
+ | |valign="top"|Write the specified string to the log. | ||
+ | |- | ||
+ | |valign="top"|[[Lianja_Methods#logEvent|Lianja.logEvent()]] | ||
+ | |valign="top"|Write the specified string to the [[Troubleshooter#Performance Metrics|Performance Metrics]] tab in the [[Troubleshooter]]. | ||
+ | |- | ||
+ | |valign="top"|[[Lianja_Methods#writeDebug|Lianja.writeDebug()]] | ||
+ | |valign="top"|Write the specified string to the debug file. | ||
+ | |- | ||
+ | |valign="top"|[[Lianja_Methods#writeError|Lianja.writeError()]] | ||
+ | |valign="top"|Write the specified string to the console. | ||
+ | |- | ||
+ | |valign="top"|[[Lianja_Methods#writeLog|Lianja.writeLog()]] | ||
+ | |valign="top"|Write the specified string to the log (desktop) or JavaScript Console (web/mobile). | ||
+ | |- | ||
+ | |valign="top"|[[Lianja_Methods#writeOutput|Lianja.writeOutput()]] | ||
+ | |valign="top"|Write the specified string to the Output Window (desktop) or JavaScript Console (web/mobile). | ||
+ | |- | ||
+ | |} | ||
− | + | ==Exception Handling== | |
+ | ===LianjaScript=== | ||
+ | TRY...CATCH...FINALLY is a command structure to handle errors and exceptions within a block of code. The <tryCommands> which follow the TRY statement are executed. If no error occurs in the <tryCommands> program execution continues from the FINALLY statement. If an error occurs, program execution jumps immediately to the CATCH statement. RETURN statements should not be issued within a TRY... ENDTRY block. | ||
− | < | + | <code lang="recital"> |
− | + | try | |
− | </ | + | use example exclusive |
+ | catch | ||
+ | messageBox("Unable to open example table") | ||
+ | endtry | ||
+ | |||
+ | //Another example | ||
+ | try | ||
+ | use example exclusive | ||
+ | catch to oExc | ||
+ | if oExc.message = "ALIAS name already in use" | ||
+ | select example | ||
+ | exit | ||
+ | else | ||
+ | messageBox("Unable to open example table") | ||
+ | endif | ||
+ | endtry | ||
+ | |||
+ | //Another example | ||
+ | try | ||
+ | ? [Outer Try] | ||
+ | try | ||
+ | use example exclusive | ||
+ | catch to oExc | ||
+ | oExc.UserValue = "Nested CATCH message: Unable to handle" | ||
+ | ?[: Nested Catch] | ||
+ | ?[ Inner Exception Object: ] | ||
+ | ?[ Error: ] + str(oExc.ErrorNo) | ||
+ | ?[ LineNo: ] + str(oExc.LineNo) | ||
+ | ?[ Message: ] + oExc.Message | ||
+ | ?[ Procedure: ] + oExc.Procedure | ||
+ | ?[ StackLevel: ] + str(oExc.StackLevel) | ||
+ | ?[ LineContents: ] + oExc.LineContents | ||
+ | ?[ UserValue: ] + oExc.UserValue | ||
+ | throw oExc | ||
+ | finally | ||
+ | ?[: Nested FINALLY executed ] | ||
+ | endtry | ||
+ | catch to oExc1 | ||
+ | ?[: Outer CATCH ] | ||
+ | ?[ Outer Exception Object: ] | ||
+ | ?[ Error: ] + str(oExc1.ErrorNo) | ||
+ | ?[ LineNo: ] + str(oExc1.LineNo) | ||
+ | ?[ Message: ] + oExc1.Message | ||
+ | ?[ Procedure: ] + oExc1.Procedure | ||
+ | ?[ StackLevel: ] + str(oExc1.StackLevel) | ||
+ | ?[ LineContents: ] + oExc1.LineContents | ||
+ | ?[ ->UserValue becomes inner exception THROWn from nested TRY/CATCH ] | ||
+ | if oExc1.UserValue.Message = "ALIAS name already in use" | ||
+ | select example | ||
+ | endif | ||
+ | finally | ||
+ | ?[: FINALLY executed ] | ||
+ | endtry | ||
+ | </code> | ||
+ | |||
+ | ===JavaScript=== | ||
+ | The try...catch statement marks a block of statements to try, and specifies a response, should an exception be thrown. | ||
+ | |||
+ | <code lang="javascript"> | ||
+ | try { | ||
+ | throw 'myException'; // generates an exception | ||
+ | } | ||
+ | catch (e) { | ||
+ | // statements to handle any exceptions | ||
+ | logMyErrors(e); // pass exception object to error handler | ||
+ | } | ||
+ | </code> | ||
− | + | ===Python=== | |
− | = | + | <code lang="python"> |
+ | try: | ||
+ | print(x) | ||
+ | except: | ||
+ | print("An exception occurred") | ||
+ | </code> | ||
[[Category:Documentation]] | [[Category:Documentation]] | ||
+ | [[Category:Commands]] | ||
+ | [[Category:Functions]] |
Latest revision as of 05:40, 11 April 2024
Debugging is one of the most important skills for a developer. Software development is all about writing code, making mistakes, and fixing them.
Strong debugging skills minimize the development cycle by allowing developers to pinpoint bugs quicker, make fixes that actually address the problems encountered, and verify the modifications are correct. This is particularly important as the code gets more complex.
Lianja App Builder is quite unique in that as you develop an App you are working directly on live data running live dynamically compiled code. This development paradigm encourages agile development and to assist you further, Lianja App Builder provides some very powerful graphical debugging tools for you to use.
Contents
Troubleshooter
The Troubleshooter provides a tabbed interface bringing together debugging, tracing and performance metrics to assist you in testing and tuning your Apps.
Desktop Tab
The Desktop Tab contains the following:
Tab | Description |
---|---|
Debugger | Contains the LianjaScript Debugger. |
Python Debugger | Contains the Python Debugger. |
JavaScript Debugger | Contains the JavaScript Debugger. |
Error Viewer | Contains error message output. |
Debugout | Contains debugout message output. |
Debug File | Contains debug information in the event of an error. |
Trace File | Contains debug tracing information. |
UIState Trace | Contains tracing information about UI State transition operations. |
Performance Metrics | Contains tracing and performance metrics for internal operations and events to allow you to see how events are fired and handled in your code and help you in performance tuning. |
Profiler Metrics | Contains Profiler environment settings and data when a LianjaScript prg is profiled in the Apps Workspace. |
Server Tab
The Server Tab contains the following:
Tab | Description |
---|---|
Error Viewer | Contains server error message output. |
LianjaScript Debugging Commands
debugout
With set debugout on, the debugout command can be used to log text messages to the debug.txt file in the Lianja debug sub-directory and displayed in the Troubleshooter Debugout Tab. The debugout command is ignored if set debugout is off.
// debugdoc.prg set debugout on debugout "about to open database" open database southwind debugout "about to open table" use example replace all available with limit - balance debugout "after replace" close databases debugout "after close data" set debugout off // Following line will not be logged: debugout "no need to log this" // end
debug.txt contents:
Debugout called from DEBUGDOC at line 3: about to open database Debugout called from DEBUGDOC at line 5: about to open table Debugout called from DEBUGDOC at line 8: after replace Debugout called from DEBUGDOC at line 10: after close data
set debug
With set debug on, debugging and error information is logged to the debug text file in the lianja debug sub-directory and displayed in the Troubleshooter Debug File Tab. By default, set debug is off. The debugging information will contain a valuable insight into the internal code so when trying to track down a hard to locate bug set debug on may be your life saver.
set debugtrace
With set debugtrace on, a trace of command execution is included in the debug text file output when set debug is on. By default, set debugtrace is off.
set debugcompile
With set debugcompile on, the compiler includes debugging information in the compiled code file. This information is then included in the debug text file output when set debug is on. By default, set debugcompile is off.
set errorlogging
With set errorlogging on, errors are logged to the debug text file. By default, set errorlogging is ON.
Lianja System Object Methods
The following cross platform and cross language Lianja system object text logging methods are available:
Method | Description |
---|---|
Lianja.console() | Write the specified string to the console output window. |
Lianja.log() | Write the specified string to the log. |
Lianja.logEvent() | Write the specified string to the Performance Metrics tab in the Troubleshooter. |
Lianja.writeDebug() | Write the specified string to the debug file. |
Lianja.writeError() | Write the specified string to the console. |
Lianja.writeLog() | Write the specified string to the log (desktop) or JavaScript Console (web/mobile). |
Lianja.writeOutput() | Write the specified string to the Output Window (desktop) or JavaScript Console (web/mobile). |
Exception Handling
LianjaScript
TRY...CATCH...FINALLY is a command structure to handle errors and exceptions within a block of code. The <tryCommands> which follow the TRY statement are executed. If no error occurs in the <tryCommands> program execution continues from the FINALLY statement. If an error occurs, program execution jumps immediately to the CATCH statement. RETURN statements should not be issued within a TRY... ENDTRY block.
try use example exclusive catch messageBox("Unable to open example table") endtry //Another example try use example exclusive catch to oExc if oExc.message = "ALIAS name already in use" select example exit else messageBox("Unable to open example table") endif endtry //Another example try ? [Outer Try] try use example exclusive catch to oExc oExc.UserValue = "Nested CATCH message: Unable to handle" ?[: Nested Catch] ?[ Inner Exception Object: ] ?[ Error: ] + str(oExc.ErrorNo) ?[ LineNo: ] + str(oExc.LineNo) ?[ Message: ] + oExc.Message ?[ Procedure: ] + oExc.Procedure ?[ StackLevel: ] + str(oExc.StackLevel) ?[ LineContents: ] + oExc.LineContents ?[ UserValue: ] + oExc.UserValue throw oExc finally ?[: Nested FINALLY executed ] endtry catch to oExc1 ?[: Outer CATCH ] ?[ Outer Exception Object: ] ?[ Error: ] + str(oExc1.ErrorNo) ?[ LineNo: ] + str(oExc1.LineNo) ?[ Message: ] + oExc1.Message ?[ Procedure: ] + oExc1.Procedure ?[ StackLevel: ] + str(oExc1.StackLevel) ?[ LineContents: ] + oExc1.LineContents ?[ ->UserValue becomes inner exception THROWn from nested TRY/CATCH ] if oExc1.UserValue.Message = "ALIAS name already in use" select example endif finally ?[: FINALLY executed ] endtry
JavaScript
The try...catch statement marks a block of statements to try, and specifies a response, should an exception be thrown.
try { throw 'myException'; // generates an exception } catch (e) { // statements to handle any exceptions logMyErrors(e); // pass exception object to error handler }
Python
try: print(x) except: print("An exception occurred")
Pages in category "Error Handling"
The following 37 pages are in this category, out of 37 total.
ABCDE |
E cont.LMORS |
S cont.T |