You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Luojiale
3557013fe8
Add w5 to w11 projects: shape inheritance, animal interface, exception handling, generics, maven project, repository with analyze command, exception hierarchy with retry
|
3 weeks ago |
| .. |
|
ExceptionDemo.class
|
Add w5 to w11 projects: shape inheritance, animal interface, exception handling, generics, maven project, repository with analyze command, exception hierarchy with retry
|
3 weeks ago |
|
ExceptionDemo.java
|
Add w5 to w11 projects: shape inheritance, animal interface, exception handling, generics, maven project, repository with analyze command, exception hierarchy with retry
|
3 weeks ago |
|
NetworkException.class
|
Add w5 to w11 projects: shape inheritance, animal interface, exception handling, generics, maven project, repository with analyze command, exception hierarchy with retry
|
3 weeks ago |
|
NetworkException.java
|
Add w5 to w11 projects: shape inheritance, animal interface, exception handling, generics, maven project, repository with analyze command, exception hierarchy with retry
|
3 weeks ago |
|
README.md
|
Add w5 to w11 projects: shape inheritance, animal interface, exception handling, generics, maven project, repository with analyze command, exception hierarchy with retry
|
3 weeks ago |
|
RetryUtils.class
|
Add w5 to w11 projects: shape inheritance, animal interface, exception handling, generics, maven project, repository with analyze command, exception hierarchy with retry
|
3 weeks ago |
|
RetryUtils.java
|
Add w5 to w11 projects: shape inheritance, animal interface, exception handling, generics, maven project, repository with analyze command, exception hierarchy with retry
|
3 weeks ago |
|
UrlFormatException.class
|
Add w5 to w11 projects: shape inheritance, animal interface, exception handling, generics, maven project, repository with analyze command, exception hierarchy with retry
|
3 weeks ago |
|
UrlFormatException.java
|
Add w5 to w11 projects: shape inheritance, animal interface, exception handling, generics, maven project, repository with analyze command, exception hierarchy with retry
|
3 weeks ago |
|
UrlValidator.class
|
Add w5 to w11 projects: shape inheritance, animal interface, exception handling, generics, maven project, repository with analyze command, exception hierarchy with retry
|
3 weeks ago |
|
UrlValidator.java
|
Add w5 to w11 projects: shape inheritance, animal interface, exception handling, generics, maven project, repository with analyze command, exception hierarchy with retry
|
3 weeks ago |
Java 异常体系设计文档
1. 异常层次设计
1.1 未检查异常 (RuntimeException)
- UrlFormatException:继承自 RuntimeException,用于处理 URL 格式校验失败
1.2 已检查异常 (Exception)
- NetworkException:继承自 Exception,用于处理网络相关问题
- 支持链式异常 (cause)
- 提供网络操作的上下文信息
2. 异常设计原则
2.1 Checked/Unchecked 选择
- UrlFormatException (Unchecked):因为 URL 格式校验是编程错误,可以通过预检查避免,使用 Unchecked 异常更合理
- NetworkException (Checked):因为网络问题是不可预测的外部因素,使用 Checked 异常强制调用者处理
2.2 异常包装
- 所有异常都保留原始异常信息 (cause)
- 使用链式异常避免根因丢失
- 提供构造函数支持 cause 链
2.3 上下文信息
- UrlFormatException 保存无效的 URL
- NetworkException 支持传递详细的错误信息
- 异常消息包含足够的上下文帮助调试
3. 重试机制
3.1 指数退避策略
- 基础等待时间:500ms
- 计算公式:
wait = base * 2^attempt
- 最大重试次数:5次
- 等待时间示例:500ms, 1000ms, 2000ms, 4000ms, 8000ms
4. AI 架构审计请求
作为Java架构师,请审查我的异常层次设计:Checked/Unchecked选择是否合理?异常包装是否丢失根因?日志是否包含足够上下文?
5. 文件列表
- UrlFormatException.java
- NetworkException.java
- RetryUtils.java
- UrlValidator.java
- ExceptionDemo.java