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

Ron Teitelbaum Ron at USMedRec.com
Sat Apr 19 00:31:07 UTC 2008


Hi Stephen,

The problem you are having is that you are trying to handle an error in a
different thread.  The handlers work when they wrap code on the same thread.
If the code can not crawl up the stack and find your handler then it doesn't
work.  So when you run your exception code it finds no handler and just
brings up a no handler exception.

Since you are trying to coordinate multiple threads you will need something
a bit more complicated although there are a few tricks which are even more
complicated using the context to signal the exception (more of an advanced
topic).  

Take a look at SharedQueue and consider having the one method feed something
into the queue that the other reads.

Ron Teitelbaum



> From: Stephen
> 
> 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