首页 > 其他分享 >无涯教程-Clojure - agent-error函数

无涯教程-Clojure - agent-error函数

时间:2023-10-29 13:32:01浏览次数:30  
标签:lang clojure java invoke clj 无涯 agent error main

如果代理失败,则返回在代理的异步操作期间抛出的异常,如果代理没有失败,则返回nil。

agent-error - 语法

(agent-error agentname)

参数      -  " agentname"是应该为其设置agent-error函数的代理。

返回值  -  如果代理失败,则返回在代理的异步操作过程中引发的异常。如果代理没有失败,则返回nil。

agent-error - 示例

以下程序显示了有关如何使用它的示例。

(ns clojure.examples.example
   (:gen-class))
(defn Example []
   (def my-date (agent(java.util.Date.)))
   (send my-date + 100)
   (await-for 100 my-date)
   (println (agent-error my-date)))
(Example)

在上面的程序中,我们通过增加错误的日期变量的值来强制导致异常发生。这将导致异常,并在" prinltn"语句的帮助下将其发送到屏幕。

上面的程序产生以下输出。

Exception in thread "main" java.lang.RuntimeException: Agent is failed, needs
start, compiling:(C:\Users\Administrator\demonew\src\demonew\main.clj:9:1)
   at clojure.lang.Compiler.load(Compiler.java:7239)
   at clojure.lang.Compiler.loadFile(Compiler.java:7165)
   at clojure.main$load_script.invoke(main.clj:275)
   at clojure.main$init_opt.invoke(main.clj:280)
   at clojure.main$initialize.invoke(main.clj:308)
   at clojure.main$null_opt.invoke(main.clj:343)
   at clojure.main$main.doInvoke(main.clj:421)
   at clojure.lang.RestFn.invoke(RestFn.java:421)
   at clojure.lang.Var.invoke(Var.java:383)
   at clojure.lang.AFn.applyToHelper(AFn.java:156)
   at clojure.lang.Var.applyTo(Var.java:700)
   at clojure.main.main(main.java:37)
Caused by: java.lang.RuntimeException: Agent is failed, needs restart
   at clojure.lang.Util.runtimeException(Util.java:225)
   at clojure.lang.Agent.dispatch(Agent.java:238)
   at clojure.core$send_via.doInvoke(core.clj:1995)
   at clojure.lang.RestFn.invoke(RestFn.java:445)
   at clojure.lang.AFn.applyToHelper(AFn.java:160)
   at clojure.lang.RestFn.applyTo(RestFn.java:132)
   at clojure.core$apply.invoke(core.clj:636)
   at clojure.core$send.doInvoke(core.clj:2006)
   at clojure.lang.RestFn.invoke(RestFn.java:425)
   at clojure.core$await_for.doInvoke(core.clj:3177)
   at clojure.lang.RestFn.invoke(RestFn.java:423)
   at clojure.examples.example$Example.invoke(main.clj:6)
   at clojure.examples.example$eval12.invoke(main.clj:9)
   at clojure.lang.Compiler.eval(Compiler.java:6782)
   at clojure.lang.Compiler.load(Compiler.java:7227)
   ... 11 more

参考链接

https://www.learnfk.com/clojure/clojure-agenterror.html

标签:lang,clojure,java,invoke,clj,无涯,agent,error,main
From: https://blog.51cto.com/u_14033984/8080229

相关文章

  • 无涯教程-Clojure - Adding a New Key to the Structure函数
    由于结构是不可变的,因此可以将另一个键添加到结构中的唯一方法是创建新结构。示例(nsclojure.examples.example(:gen-class))(defnExample[](defstructEmployee:EmployeeName:Employeeid)(defemp(struct-mapEmployee:EmployeeName"Learnfk":Employeei......
  • 无涯教程-Clojure - send-off函数
    在某些情况下,为代理分配了实际上是阻止的函数。一个简单的示例是,考虑您正在从本质上是阻塞的文件中读取内容。send-off-语法(sendagentnamefunctionvalue)参数   - "agentname"是将发送函数重定向到的代理,"function"用于确定更改代理价值的方式,"value"是传递......
  • pip3 install xxx, Fatal error in launcher: Unable to create process using '"C:
    重装系统后,移动了python所在目录后,使用pip3installxx提示:Fatalerrorinlauncher:Unabletocreateprocessusing'"C:\Software\Python310\python.exe""D:\Aliwall\Software\Python310\Scripts\pip3.exe"installshutil':???????????......
  • 解决self.draw.draw_rectangle(xy, fill, 1) ValueError: y1 must be greater tha
    我尝试了很多方法,包括单不限于改labelme文件的直接报错,修改pillow包的原文件尝试注释掉raise的地方。最后都以失败告终。还有尝试重新安装最新版的包,来解决。最后经过多次尝试后发现,发生错误的地方的文件是有问题的,至于是什么问题到现在也不知道,那就删除最后停止位置时......
  • 无涯教程-Clojure - Immutable Nature函数
    默认情况下,结构也是不可变的,因此,如果我们尝试更改特定键的值,则它不会更改。Immutable-示例(nsclojure.examples.example(:gen-class))(defnExample[](defstructEmployee:EmployeeName:Employeeid)(defemp(struct-mapEmployee:EmployeeName"Learnfk"......
  • nfs-client-provisioner 启动失败(容器日志:panic: error creating self-signed certifi
    1、NFS服务部署#cat/etc/exports/data/kubernetes/*(insecure,rw,sync,no_root_squash)/data/nfs/*(insecure,rw,sync,no_root_squash)在node-1-231验证nfs服务#showmount-e192.168.1.230Exportlistfor192.168.1.230:/data/nfs/*/data/kubernetes/*......
  • 无涯教程-Clojure - Accessing Individual Fields函数
    可以通过与结构对象一起访问键来访问结构的各个字段。AccessingIndividual-语法:keystructure-name参数   - "key"是结构中的键值,"structure-name"是作为相应关键字的结构。返回值 - 将返回与键关联的值。以下程序显示了有关如何使用它的示例。AccessingI......
  • 无涯教程-Clojure - struct-map函数
    通过显式定义将哪些值分配给结构中的哪些键,此函数用于将值专门分配给键值。struct-map-语法(struct-mapstructnamekeynvaluen….)参数   - "structname"是要赋予结构的名称,"keyn和valuen"是需要分配给该结构的键值。返回值 - 返回一个结构对象,其值映射......
  • 无涯教程-Clojure - defstruct函数
    该函数用于定义所需的结构。defstruct-语法(defstructstructnamekeys)参数   - "structname"是要赋予结构的名称,"keys"是需要作为结构一部分的键。返回值 - 返回结构对象。defstruct-示例以下程序显示了有关如何使用它的示例。(nsclojure.examples.......
  • 无涯教程-Clojure - vary-meta函数
    返回与原始对象具有相同类型和值的对象,但具有组合的元数据。vary-meta-语法(vary-metaobjnew-meta)参数   - 'obj'是要检查是否有任何元数据与之关联的对象,"new-meta"是需要与对象关联的元数据值。返回值 -返回与原始对象具有相同类型和值的对象,但具有组合......