Database Reference
In-Depth Information
:debug: [1990 "|0028677|" "|C00186288|" "|N00007967|" 2000
"06/15/1990" "|C4100|" "|24K|" "|D|" "|H6WA05023|"] => [1990
"|0028687|" "|C00186288|" "|N00002497|" 500 "07/18/1990" "|C4100|"
"|24K|" "|D|" "|H6SC03025|"]
:debug: [1990 "|0028687|" "|C00186288|" "|N00002497|" 500
"07/18/1990" "|C4100|" "|24K|" "|D|" "|H6SC03025|"] => [1990
"|0028706|" "|C00186288|" "|N00007763|" 1000 "09/28/1990"
"|C4100|" "|24K|" "|D|" "|S8OR00017|"]
There's more...
This is a good option to debug output if you need a lot of lexibility. However, if all you
need is to track function calls, arguments, and outputs, clojure.tools.trace
( https://github.com/clojure/tools.trace ) is better. It does this and only
this, and it's also less intrusive on your program's structure.
Recovering from errors in agents
Since agents run in a thread pool, the way exceptions are signaled and handled becomes
an issue. Does the offending message function simply stop running? Does the agent stop?
What happens to the Exception instance?
Clojure has several mechanisms to deal with errors in agent functions. We'll walk through
them in this recipe.
How to do it…
The agent's error mode and error handler determine how it handles errors. The error mode
can be set when the agent is created or with the function set-error-mode! , and the error
handler is set with set-error-handler! .
Failing on errors
The default error mode is :fail . If we don't specify an error mode when we create an agent,
this is what it gets. With this error mode, when one of the agent's message functions throws
an exception, the agent stops processing any more messages and stores the exception. We
can retrieve the exception with agent-error , and we can start processing it again with
restart-agent :
user=> (def agent-99 (agent 0))
#'user/agent-99
user=> (send agent-99 #(/ 100 %))
#<Agent@aa711 FAILED: 0>
user=> (agent-error agent-99)
#<ArithmeticExceptionjava.lang.ArithmeticException: Divide by zero>
 
Search WWH ::




Custom Search