如何使用本地异常类?
我想在ABAP中编写和使用本地异常类。保持简单有助于我理解,所以我简化了我的情况:
假设我有一个带有“withdraw”方法的帐户类。如果我提款超过当前余额允许的金额,则应引发“account_overdrawn”异常类别。
I want to write and use a local exception class in ABAP. Keeping it easy, helps me to understand, so I simplified my case:
Lets say I have an account class with the method "withdraw". If I withdrew more than my current balance allows, an "account_overdrawn" exception class should be raised.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用语句 RAISE EXCEPTION TYPE (类名),假设类名在您执行此操作的范围内。
根据您声明类的方式,您可能必须将某些内容传递给其构造函数。 RAISE EXCEPTION TYPE 语句的工作方式与 CREATE OBJECT 类似,但您正在创建异常对象的实例。
You must use the statement RAISE EXCEPTION TYPE (class name), assuming that the class name is in the scope in which you are doing this.
Depending on how you declared your class, you may have to pass something to its constructor. The RAISE EXCEPTION TYPE statement works just like CREATE OBJECT, but instead, you are creating an instance of an exception object.