lotusphere 2007 bp312: trap and manage your errors easily, efficiently and reliably
TRANSCRIPT
®
BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably Rob McDonagh
Julian Robichaux
ATTENTION
This is a Lotusphere presentation.
If you did not mean to attend Lotusphere, you are in the wrong room.
Let's start with one
embarrassing truth...
...errors happen
Look at all the eraser marks
But there's hope
Welcome to the 1-Step
Program for
Error Recovery
We like to call it...
Logging
Okay, maybe it's
really 2 steps
Log
Trap
So how do you know
that there are errors
in your code?
Because you wrote it
All code is error-prone
Here's an example:
Function AddOne (i As Integer) As IntegerAddOne = i + 1
End Function
Why do we need error-trapping
for something measly like that?
Try this:
Print "32,768 = " & AddOne(32767)
Function AddOne (i As Integer) As IntegerAddOne = i + 1
End Function
You may realize that
you could simply “fix”
the function to return
a Long instead
But how would you know
it had to be fixed?
Because a USER
calls you?
Maybe the CEO?
Or maybe it just keeps
failing silently and
causing weird problems
What do we recommend?
STEP 1:Trap your errors
Function AddOne (i As Integer) As IntegerOn Error Goto trapErrorAddOne = i + 1Exit Function
trapError:Messagebox "Sorry, bad number"
End Function
What happened?
What's this “No Resume” stuff?
An error block is like
its own separate chunk
of code.
You have to tell it what
to do when it's done.
Options:Exit Function/SubResume <block>Resume NextResume 0End (usually a bad idea)
So, let's say we convinced you.
You add error-handling to all of
your code.
You go, girl!
But what good does that
really do you?
Now instead of this when
an error happens...
... your users get this:
Great... thanks...
This hasn't helped at all!!!
We still have a bunch
of errors to deal with.
Don't worry.
Help is on the way.
STEP 2:Log your errors
Not this kind of log
What if...?
Instead of displaying the error
we wrote it to a database...
Using a NotesLog
is the “native” way
to do this:
LogActionLogErrorLogEvent
It works, but it's a little...
ugly
Well, pretty basic anyway
It's not a bad system,
but think of the important
information that's missing
User nameUser ACL accessFunction nameError line numberDatabase nameServer nameNotes client versionEtc.
That's okay, we can just
add it to our error block
Function AddOne (i As Integer) As IntegerOn Error Goto trapErrorAndLogEverythingAddOne = i + 1Exit Function
trapErrorAndLogEverything:Dim session As New NotesSessionDim db As NotesDatabaseSet db = session.CurrentDatabase
Call currentLog.LogError(Err, "Error on line " & Erl & _": " & Error & Chr(10) & _"User name: " & session.CommonUserName & _Chr(10) & "Function name: ThisFunctionName" & _Chr(10) & "Database name: " & db.Title & _Chr(10) & "Server name: " & db.Server & _Chr(10) & "ACL Access Level: " & db.CurrentAccessLevel & _Chr(10) & "Roles: " & Join(Evaluate("@UserRoles"), "; ") & _Chr(10) & "Notes client version: " & session.NotesBuildVersion)
End Function
That would be useful, but a tad...
long-winded...
and annoying to type
What if...?
We could just add a single
line of code, like this:
Function AddOne (i As Integer) As IntegerOn Error Goto trapErrorAddOne = i + 1Exit Function
trapError:Call LogError()Exit Function
End Function
And get output like this:
APPLAUSE
So how do we get from
here:
to there?
OpenLog
It's free.
It's open-source.
It's waiting for you.
http://www.openntf.org
How do you get it?
How do you use it?
DownloadCopy to serverAdjust ACLCopy Script LibraryAdd “LogError”
Too tough?
Let's do a quick demo.
DEMO
Where can I use this?
Anywhere you can typeLotusScript or Java
LotusScriptAgents
JavaAgents
FormsScript
Libraries
Views
Buttons
Actions
DEMO
Even JavaScript!
(psst. Think
“Web 2.0”) NEW!
DEMO
Great, I'm logging errors.
Now what?
How do I know they happened?
Notifications!
RSS Feeds!
NEW!
DEMO
DDM!
Ask your Admin, or read the Redbook:
http://www.redbooks.ibm.com/abstracts/REDP4089.html
Advanced topics:
Using with local/offline database replicasDealing with multiple servers and directoriesExtending and customizing
DEMO
We're out of time
Quick FAQ:Does it work on the client AND the server?What if the log database isn't there? Does my application break?Is it really free?Does anyone use this?How do you guys make money on it?Why don't I just write my own?
Look us up online:
Rob McDonagh = www.CaptainOblivious.com
Julian Robichaux = www.nsftools.com
Thanks!
© IBM Corporation 2007. All Rights Reserved.
The workshops, sessions and materials have been prepared by IBM or the session speakers and reflect their own views. They are provided for informational purposes only, and are neither intended to, nor shall have the effect of being, legal or other guidance or advice to any participant. While efforts were made to verify the completeness and accuracy of the information contained in this presentation, it is provided AS IS without warranty of any kind, express or implied. IBM shall not be responsible for any damages arising out of the use of, or otherwise related to, this presentation or any other materials. Nothing contained in this presentation is intended to, nor shall have the effect of, creating any warranties or representations from IBM or its suppliers or licensors, or altering the terms and conditions of the applicable license agreement governing the use of IBM software.
References in this presentation to IBM products, programs, or services do not imply that they will be available in all countries in which IBM operates. Product release dates and/or capabilities referenced in this presentation may change at any time at IBM’s sole discretion based on market opportunities or other factors, and are not intended to be a commitment to future product or feature availability in any way. Nothing contained in these materials is intended to, nor shall have the effect of, stating or implying that any activities undertaken by you will result in any specific sales, revenue growth or other results.
Performance is based on measurements and projections using standard IBM benchmarks in a controlled environment. The actual throughput or performance that any user will experience will vary depending upon many factors, including considerations such as the amount of multiprogramming in the user's job stream, the I/O configuration, the storage configuration, and the workload processed. Therefore, no assurance can be given that an individual user will achieve results similar to those stated here.
All customer examples described are presented as illustrations of how those customers have used IBM products and the results they may have achieved. Actual environmental costs and performance characteristics may vary by customer.
IBM, the IBM logo, Lotus, Lotus Notes, Notes, Domino, Domino.Doc, Domino Designer, Lotus Enterprise Integrator, Lotus Workflow, Lotusphere, QuickPlace, Sametime, WebSphere, Workplace, Workplace Forms, Workplace Managed Client, Workplace Web Content Management, AIX, AS/400, DB2, DB2 Universal Database, developerWorks, eServer, EasySync, i5/OS, IBM Virtual Innovation Center, iSeries, OS/400, Passport Advantage, PartnerWorld, Rational, Redbooks, Software as Services, System z, Tivoli, xSeries, z/OS and zSeries are trademarks of International Business Machines Corporation in the United States, other countries, or both.
Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both.
Microsoft and Windows are trademarks of Microsoft Corporation in the United States, other countries, or both.
Intel and Pentium are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries.
UNIX is a registered trademark of The Open Group in the United States and other countries.
Linux is a registered trademark of Linus Torbvalds in the United States, other countries, or both.
Other company, product, or service names may be trademarks or service marks of others.
All references to Acme, Renovations and Zeta Bank refer to a fictitious company and are used for illustration purposes only.