[squeak-dev] how to catch Exception in worker thread: LDAPLayer

Stephen sdw2 at shineonline.co.nz
Sat Apr 19 00:15:55 UTC 2008


I'm using the LDAPlayer library to authenticate username/password in a 
login form via a lookup to an LDAP database. If a wrong password is 
entered, then LDAPlayer throws an LDAPException in a worker thread but 
doesn't report the exception back to the calling thread.

My problem is I am fairly new to Smalltalk and I don't know how to work 
around this situation. What I would like is to get the LDAPException 
back to my application so I can handle it as required.

-------------------------------------------------

In case it helps, here are some code pieces:

the call to do the authentication:

[  conn := LDAPConnection to: host port: 389.
    [[ req := conn bindAs: userDN credentials: pwd] on:
     Error do:[:ex |    Transcript show: ex messageText].
    [result := req result] on: LDAPException do:
     [:ex |Transcript show: ex messageText].
] ensure: [conn disconnect].

If wrong password is given, LDAPLayer throws an exception when 
evaluating "req result" but the Transcript message in my application is 
never called. In fact the workerthread (shown below) gets blocked by the 
exception.

  -----------------

LDAPLayer initiates a "WorkerThread" class with the following method
start
    | process |
    running _ true.
    process _ [
     [running] whileTrue: [
         |  element  |
         element _ LDAPMessage newFrom: sockStream.
         Transcript show: '********* READ ONE OF:  ', element asString; cr.
         self dispatchMessage: element.
     ]
    ] fork.
    ^ process
--------------------

When the debug window comes up, the top method on the stack is 
"LDAPResult checkForExceptions", code shown below.

checkForExceptions
    (resultCode = 0 or: [resultCode = 5] or: [resultCode = 6])
     ifFalse: [
        | ex |
        ex _ LDAPException newWithCode: resultCode.
        ex signal: errorMessage ]


Note: confirmed commenting out the 'ex signal' line stops the debug 
window from displaying.



More information about the Squeak-dev mailing list