Comments (3)
这种写法没问题的, 很多框架都这么用.但是最好的方式肯定是日志框架.
捕获的目的就是打印, 要么日志框架打印,要么system.
抛出一个new 异常 也是打印,printStackTrace().
有时候不方便引入日志框架,又不想直接system.
比如一个方法未实现逻辑,就可以直接抛出new 异常,当执行一个逻辑发生错误,也可以抛出new异常.
捕获异常后,直接抛出new异常,最终还是通过system打印的(会阻塞一下,毕竟是同步打印的,所以才会有日志框架代替,因为日志框架都支持异步).
如果不能忍受抛new异常的阻塞,那就用日志框架代替.
from guide-rpc-framework.
把异常统一封装成自定义异常RpcException,同时将真正的异常作为参数。比如redis客户端,操作的时候可能出现网络超时,这种超时统一封装为redis自定义异常。
切记不可滥用。
from guide-rpc-framework.
之前这里有一点参考 dubbo 的做法。其实,我觉得直接将异常通过log.error
打印出来就好。
from guide-rpc-framework.
Related Issues (20)
- 问个问题 HOT 1
- github.javaguide.provider.impl.ZkServiceProviderImpl类中为什么有serviceMap,还需要registeredService这个set去保存接口名? HOT 1
- 无法远程调用无参方法 HOT 2
- 请问如果远程接口有多个实现类怎么办 HOT 1
- 请问自定义RPC协议的设计思路是如何? HOT 1
- 请问服务宕机了,zk能感知到吗 HOT 4
- SPI实现的一点小疑问 HOT 2
- RPC服务调用方法参数传递为Java类对象 HOT 3
- 发现个小问题 HOT 1
- CollectionUtils & StringUtils HOT 1
- 一致性hash中,相同入参无法路由到同一个服务 HOT 3
- 关于服务提供者下线后重新上线,不通过重启客户端无法被服务提供者感知 HOT 1
- 有个问题有人可以解答一下吗? HOT 1
- ExtensionLoader类获取实现类的时候,为什么要加双重锁 HOT 1
- 并发情况下,应该会创建多条连接吧?
- InetAddress.getLocalHost().getHostAddress(); HOT 1
- zookeeper 的 watch 机制导致的问题 HOT 1
- zookeeper版本和curator版本不匹配导致的问题 HOT 1
- 获取rpcServiceName的时候直接用接口名、version、group相加是不是不太好 HOT 1
- 序列化方式Kryo写错了
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from guide-rpc-framework.