apex - Apex 自定义异常并使用参数创建新异常
问题描述
我从 Apex 开发人员指南中选择了以下示例。我的问题是,这段throw new OtherException('This is bad');
代码是如何工作的。由于没有定义默认/参数化构造函数,我们如何创建一个OtherException
带参数的新构造函数?
public class ExceptionExample {
public virtual class BaseException extends Exception {}
public class OtherException extends BaseException {}
public static void testExtendedException() {
try {
Integer i=0;
// Your code here
if (i < 5) throw new OtherException('This is bad');
} catch (BaseException e) {
// This catches the OtherException
System.debug(e.getMessage());
}
}
}
解决方案
推荐阅读
- swift - 如何在视图控制器之间共享集合而不来回传递它?
- amazon-web-services - 我应该使用 nginx 反向代理进行云对象存储吗?
- java - 是否可以检索字符串数组的索引?在 JAVA 中
- macos - 在 mac 上安装 pygame 时出错:错误:命令“gcc”失败,退出状态为 1
- r - 如何聚合列表列表的元素以获得一个向量?
- html - 为什么根据您在浏览器开发工具中的选择方式为同一元素显示不同的选择器?
- python - 当我运行 GEKKO 优化时,我得到一个“FileNotFoundError”
- elasticsearch - 如何查询时间是否在两个字段值之间
- windows - 团队留言卡
- java - 使用 NFC 标签打开应用程序时无法获得 NDEF_DISCOVERED 操作