80

Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Embed Size (px)

Citation preview

Page 1: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably
Page 2: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

®

BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably Rob McDonagh

Julian Robichaux

Page 3: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

ATTENTION

This is a Lotusphere presentation.

If you did not mean to attend Lotusphere, you are in the wrong room.

Page 4: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Let's start with one

embarrassing truth...

Page 5: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

...errors happen

Page 6: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Look at all the eraser marks

Page 7: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

But there's hope

Page 8: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Welcome to the 1-Step

Program for

Error Recovery

Page 9: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

We like to call it...

Page 10: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Logging

Page 11: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Okay, maybe it's

really 2 steps

Page 12: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Log

Trap

Page 13: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

So how do you know

that there are errors

in your code?

Page 14: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Because you wrote it

Page 15: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

All code is error-prone

Page 16: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Here's an example:

Function AddOne (i As Integer) As IntegerAddOne = i + 1

End Function

Page 17: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Why do we need error-trapping

for something measly like that?

Page 18: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Try this:

Print "32,768 = " & AddOne(32767)

Function AddOne (i As Integer) As IntegerAddOne = i + 1

End Function

Page 19: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably
Page 20: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

You may realize that

you could simply “fix”

the function to return

a Long instead

Page 21: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

But how would you know

it had to be fixed?

Page 22: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Because a USER

calls you?

Page 23: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Maybe the CEO?

Page 24: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Or maybe it just keeps

failing silently and

causing weird problems

Page 25: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably
Page 26: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

What do we recommend?

Page 27: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

STEP 1:Trap your errors

Page 28: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Function AddOne (i As Integer) As IntegerOn Error Goto trapErrorAddOne = i + 1Exit Function

trapError:Messagebox "Sorry, bad number"

End Function

Page 29: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably
Page 30: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

What happened?

What's this “No Resume” stuff?

Page 31: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

An error block is like

its own separate chunk

of code.

You have to tell it what

to do when it's done.

Page 32: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Options:Exit Function/SubResume <block>Resume NextResume 0End (usually a bad idea)

Page 33: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

So, let's say we convinced you.

You add error-handling to all of

your code.

Page 34: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

You go, girl!

Page 35: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

But what good does that

really do you?

Page 36: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Now instead of this when

an error happens...

Page 37: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

... your users get this:

Page 38: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Great... thanks...

This hasn't helped at all!!!

We still have a bunch

of errors to deal with.

Page 39: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Don't worry.

Help is on the way.

Page 40: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

STEP 2:Log your errors

Page 41: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Not this kind of log

Page 42: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

What if...?

Instead of displaying the error

we wrote it to a database...

Page 43: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Using a NotesLog

is the “native” way

to do this:

LogActionLogErrorLogEvent

Page 44: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

It works, but it's a little...

ugly

Page 45: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably
Page 46: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Well, pretty basic anyway

Page 47: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

It's not a bad system,

but think of the important

information that's missing

Page 48: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

User nameUser ACL accessFunction nameError line numberDatabase nameServer nameNotes client versionEtc.

Page 49: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

That's okay, we can just

add it to our error block

Page 50: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

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

Page 51: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

That would be useful, but a tad...

long-winded...

and annoying to type

Page 52: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

What if...?

We could just add a single

line of code, like this:

Page 53: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Function AddOne (i As Integer) As IntegerOn Error Goto trapErrorAddOne = i + 1Exit Function

trapError:Call LogError()Exit Function

End Function

Page 54: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

And get output like this:

Page 55: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably
Page 56: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

APPLAUSE

Page 57: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

So how do we get from

here:

to there?

Page 58: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

OpenLog

Page 59: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

It's free.

It's open-source.

It's waiting for you.

http://www.openntf.org

Page 60: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

How do you get it?

How do you use it?

Page 61: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

DownloadCopy to serverAdjust ACLCopy Script LibraryAdd “LogError”

Page 62: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Too tough?

Let's do a quick demo.

Page 63: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

DEMO

Page 64: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Where can I use this?

Page 65: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Anywhere you can typeLotusScript or Java

LotusScriptAgents

JavaAgents

FormsScript

Libraries

Views

Buttons

Actions

Page 66: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

DEMO

Page 67: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Even JavaScript!

(psst. Think

“Web 2.0”) NEW!

Page 68: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

DEMO

Page 69: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Great, I'm logging errors.

Now what?

How do I know they happened?

Page 70: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Notifications!

Page 71: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

RSS Feeds!

NEW!

Page 72: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

DEMO

Page 73: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

DDM!

Ask your Admin, or read the Redbook:

http://www.redbooks.ibm.com/abstracts/REDP4089.html

Page 74: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Advanced topics:

Using with local/offline database replicasDealing with multiple servers and directoriesExtending and customizing

Page 75: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

DEMO

Page 76: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

We're out of time

Page 77: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

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?

Page 78: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Look us up online:

Rob McDonagh = www.CaptainOblivious.com

Julian Robichaux = www.nsftools.com

Page 79: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

Thanks!

Page 80: Lotusphere 2007 BP312: Trap and Manage Your Errors Easily, Efficiently and Reliably

© 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.