DA.Exception
文档索引
获取完整文档索引:https://docs.canton.network/llms.txt 在进一步浏览前,可用该文件发现所有可用页面。
DA.Exception
Daml 模块 DA.Exception 的参考文档。
DA.Exception
Daml 中的异常处理。
已弃用:请使用 failWithStatus 与 FailureStatus,而非 Daml Exception。
模块概览
数据类型
type Exception = (HasThrow e, HasMessage e, HasToAnyException e, HasFromAnyException e)
异常类型类。不应直接实现,请使用 exception 语法。
类型类
class HasThrow e
Exception 约束的一部分。
方法:
throwPure : e -> t在纯上下文中抛出异常。
实例:
instance HasThrow ArithmeticErrorinstance HasThrow AssertionFailedinstance HasThrow GeneralErrorinstance HasThrow PreconditionFailed
class HasMessage e
Exception 约束的一部分。
方法:
message : e -> Text获取异常关联的错误消息。
实例:
instance HasMessage AnyExceptioninstance HasMessage ArithmeticErrorinstance HasMessage AssertionFailedinstance HasMessage GeneralErrorinstance HasMessage PreconditionFailed
class HasToAnyException e
Exception 约束的一部分。
方法:
toAnyException : e -> AnyException将异常类型转换为 AnyException。
实例:
instance HasToAnyException AnyExceptioninstance HasToAnyException ArithmeticErrorinstance HasToAnyException AssertionFailedinstance HasToAnyException GeneralErrorinstance HasToAnyException PreconditionFailed
class HasFromAnyException e
Exception 约束的一部分。
方法:
fromAnyException : AnyException -> Optional e若可能,将 AnyException 转回底层异常类型。
实例:
instance HasFromAnyException AnyExceptioninstance HasFromAnyException ArithmeticErrorinstance HasFromAnyException AssertionFailedinstance HasFromAnyException GeneralErrorinstance HasFromAnyException PreconditionFailed
class Action m => ActionThrow m
支持 throw 的 Action 类型。
方法:
throw : Exception e => e -> m t
实例:
instance ActionThrow Update
class ActionThrow m => ActionCatch m
支持 try ... catch ... 的 Action 类型。
已弃用:避免在 Daml 代码中使用 catch,优先在客户端处理错误,并用 failWithStatus 抛出。
方法:
_tryCatch : (() -> m t) -> (AnyException -> Optional (m t)) -> m t处理异常。请使用try ... catch ...语法,而非直接调用本方法。
实例:
instance ActionCatch Update
孤儿类型类实例
-
instance GetField message GeneralError Text -
instance SetField message GeneralError Text -
instance GetField message ArithmeticError Text -
instance SetField message ArithmeticError Text -
instance GetField message PreconditionFailed Text -
instance SetField message PreconditionFailed Text -
instance GetField message AssertionFailed Text -
instance SetField message AssertionFailed Text
本文由 CC Privacy Club 根据 Canton Network 官方文档(CC-BY-4.0)整理翻译,仅供学习;实现细节以官方最新版本为准。