errorhandling techniques in xpages, javascript, java...
TRANSCRIPT
![Page 1: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/1.jpg)
errorhandling techniques in XPages, Javascript, Java, Lotusscript and
@Formulas
![Page 2: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/2.jpg)
�What is error handling?�Errorhandling in:◦@Formula◦Javascript◦Lotusscript◦Java◦xPages
�Openlog
![Page 3: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/3.jpg)
Anticipate, detect and process of programming, user and environment failures or errors
Prevent partially by defensive programming
What counts is what you do with the errors
![Page 4: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/4.jpg)
![Page 5: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/5.jpg)
![Page 6: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/6.jpg)
• Loads of cryptical error messages – no info about triggered events
• No central error handling possible - be sparse with your @Formulas - use display fields for re-usable calculations
• Defensive programming (@IsError, Test DataTypes: @Elements, @IsTime, @IsNumber, @Text ...)
![Page 7: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/7.jpg)
![Page 8: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/8.jpg)
Standard try - catch routine
try {
// call a function that could error out
var result = getInvoiceNumbers(customerNumber,invoiceDate);;
}
catch (e) {
result = "Error in retrieving invoices";
}
// optional use finally runs after the try/catch block
finally {
window.Forms[0].fldname.value = result
}
Throw your own errorsif (number > 10) { throw "NumberTooHighError" }
![Page 9: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/9.jpg)
Try - catch routine based on error type
try {
var result = getInvoiceNumbers(customerNumber,invoiceDate);
}
catch (e
if e == "CustomerNumberException") {
result = "Incorrect customerNumber";
}
else if e == "DateErrorException") {
result = "Incorrect Date";
}
else result = "Error in retrieving invoices";
}
![Page 10: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/10.jpg)
To register a general errorHandler use:
(window.)onerror=functionname()
This function will have 3 input variables like:
function functionname(msg,url,line_num)
You can use these variables to log/show the error details
![Page 11: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/11.jpg)
![Page 12: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/12.jpg)
◦ use On Error blocks
◦ On Error resume next is a big nono .. you are supposed to handle things, not ignoring them
◦ You have differtent audiences: users, developers, administrators. So throw custom errors.◦ Then handle specific errors
◦ Option Declare prevents some programmatic errors◦ new! Create a template in the new 8.5.1 LS IDE for your error
handling blocks in subs and functions
![Page 13: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/13.jpg)
![Page 14: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/14.jpg)
• As with JavaScript use try - catch - finally blocks and throw/catch custom errors
Try {
List list = new ArrayList(getInvoiceNumbers(customerNumber,invoiceD
ate));
} catch ( IOException e) {
// handle/log this error
} catch ( OtherErrorException e) {
// again handle this
} catch (Exception e) {
// other errors
}
// optional
}finally {
}
![Page 15: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/15.jpg)
• Chose:o Handle errors in subfunctionso Throw the error back to higher functions
private Integer convertToInteger(String str) {
try {
Integer intObj2 = Integer.valueOf(str)
} catch (e) { // do something }
return int;
}
private Integer convertToInteger(String str) throws
NumberFormatException {
Integer intObj2 = Integer.valueOf(str)
}
![Page 16: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/16.jpg)
class CustomException extends Exception {
public CustomException(String msg){
super(msg);
}
}
public class Test {
public static void main(String[] args) {
try {
System.out.println(divide(4,0));
}
catch (CustomException e) { e.printStackTrace(); }
}
static int divide(int first,int second) throws CustomException{
if(second==0) throw new MyException("dividing by zero");
return first/second;
}
}
![Page 17: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/17.jpg)
![Page 18: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/18.jpg)
Error handling in xPages• Default errorpage on server (admin can change xsp\nsf\xsp.properties)• Set errorpage in application• Custom Error page (general, debug, specific)• Logging to AgentLog
![Page 19: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/19.jpg)
how wonderful, free stuff
![Page 20: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/20.jpg)
• JavaScript• Java
• XPages• Lotusscript
DEMO!!!!!!
![Page 21: errorhandling techniques in XPages, Javascript, Java ...vinceschuurman.com/home/ndt4.nsf/(lublogcontent... · Anticipate, detect and process of programming, user and environment failures](https://reader034.vdocument.in/reader034/viewer/2022050402/5f7fd2a2bc8fa2188e46292e/html5/thumbnails/21.jpg)
◦ Getting it to work is NOT ENOUGH! ◦ Always add errorhandling to production code◦ Thou shall avoid the use of hard coded stuff◦ When not sure: check◦ If it can go wrong, it will go wrong. At one point.◦ Think first, then build your logic◦ Do not repeat code
◦ Use only one line of code in events (click, query*)
◦ Your users are dumb ... but: you are even dumber (if you ignore them)◦ Make your code beautiful: comment not what,
but why and use meaningfull names