当前位置:网站首页>When to catch an exception and when to throw an exception- When to catch the Exception vs When to throw the Exceptions?
When to catch an exception and when to throw an exception- When to catch the Exception vs When to throw the Exceptions?
2022-07-05 02:06:00 【javail】
problem :
I have been coding in Java for a while now. I've used Java Coding for some time .But sometimes, I don't understand when I should throw the exception and when should I catch the exception. But sometimes , I don't know when to throw an exception , When should exceptions be caught .I am working on a project in which there are lot of methods. I am working on a project with many methods .The hierarchy is something like this- The hierarchy is like this ——
Method A will call Method B and Method B will call some Method C and Method C will call Method D and Method E.
So currently what I am doing is- I am throwing exceptions in all the methods and catching it in Method A and then logging as an error. So what I'm doing now is - I throw exceptions in all methods and in methods A Capture it in , Then record it as an error .
But I am not sure whether this will be the right way to do it? But I'm not sure if it's the right thing to do ?Or should I start catching exceptions in all the Methods. Or I should start catching exceptions in all methods .So that is why this confusion started in my- When should I catch the Exception vs When should I throw the exceptions. So that's why this mess started with my - When should I catch an exception and when should I throw an exception .I know it's a silly question but somehow I am struggling to understand this major concept. I know this is a stupid question , But somehow it is difficult for me to understand this main concept .
Can someone give me a detailed example of When to catch the Exception vs When to throw the Exceptions
so that my concepts gets cleared on this? Someone can give me a detailed example , explain When to catch the Exception vs When to throw the Exceptions
So that my concept can be clarified ?And in my case, should I keep on throwing the exception and then catch it in the main calling Method A? As far as I'm concerned , I should keep throwing exceptions , Then call the method in the main A Capture it in ?
Solution :
Reference resources : https://stackoom.com/en/question/1GNHe边栏推荐
- PHP 基础篇 - PHP 中 DES 加解密详解
- CAM Pytorch
- Yolov5 model training and detection
- One plus six brushes into Kali nethunter
- 187. Repeated DNA sequence - with unordered_ Map basic content
- Huawei machine test question: longest continuous subsequence
- The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
- Application and Optimization Practice of redis in vivo push platform
- Data guard -- theoretical explanation (III)
- Interesting practice of robot programming 14 robot 3D simulation (gazebo+turtlebot3)
猜你喜欢
Go RPC call
"C zero foundation introduction hundred knowledge and hundred cases" (72) multi wave entrustment -- Mom shouted for dinner
Application and Optimization Practice of redis in vivo push platform
流批一體在京東的探索與實踐
A tab Sina navigation bar
PHP wechat official account development
Five ways to query MySQL field comments!
JVM's responsibility - load and run bytecode
Video display and hiding of imitation tudou.com
【附源码】基于知识图谱的智能推荐系统-Sylvie小兔
随机推荐
R语言用logistic逻辑回归和AFRIMA、ARIMA时间序列模型预测世界人口
Exploration of short text analysis in the field of medical and health (II)
流批一體在京東的探索與實踐
A label colorful navigation bar
He was laid off.. 39 year old Ali P9, saved 150million
"2022" is a must know web security interview question for job hopping
One plus six brushes into Kali nethunter
Go RPC call
[技术发展-26]:新型信息与通信网络的数据安全
Official announcement! The third cloud native programming challenge is officially launched!
Interpretation of mask RCNN paper
PHP 基础篇 - PHP 中 DES 加解密详解
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
Process scheduling and termination
STM32 series - serial port UART software pin internal pull-up or external resistance pull-up - cause problem search
Win: add general users to the local admins group
Win:使用 PowerShell 检查无线信号的强弱
Practical case of SQL optimization: speed up your database
MySQL backup and recovery + experiment
Codeforces Round #770 (Div. 2) ABC