当前位置:网站首页>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边栏推荐
- Five ways to query MySQL field comments!
- [technology development-26]: data security of new information and communication networks
- Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery
- Restful Fast Request 2022.2.1发布,支持cURL导入
- Serious bugs with lifted/nullable conversions from int, allowing conversion from decimal
- Can financial products be redeemed in advance?
- [source code attached] Intelligent Recommendation System Based on knowledge map -sylvie rabbit
- One plus six brushes into Kali nethunter
- Summary and practice of knowledge map construction technology
- RichView TRVStyle MainRVStyle
猜你喜欢
[技术发展-26]:新型信息与通信网络的数据安全
[technology development-26]: data security of new information and communication networks
Visual explanation of Newton iteration method
Tucson will lose more than $400million in the next year
线上故障突突突?如何紧急诊断、排查与恢复
Phpstrom setting function annotation description
Action News
R language uses logistic regression and afrima, ARIMA time series models to predict world population
Win:使用 PowerShell 检查无线信号的强弱
Introduce reflow & repaint, and how to optimize it?
随机推荐
RichView TRVStyle MainRVStyle
MySQL REGEXP:正则表达式查询
STL container
WCF: expose unset read-only DataMember property- WCF: Exposing readonly DataMember properties without set?
STM32 series - serial port UART software pin internal pull-up or external resistance pull-up - cause problem search
Interesting practice of robot programming 14 robot 3D simulation (gazebo+turtlebot3)
Three properties that a good homomorphic encryption should satisfy
JVM's responsibility - load and run bytecode
Missile interception -- UPC winter vacation training match
Pgadmin 4 V6.5 release, PostgreSQL open source graphical management tool
Practice of tdengine in TCL air conditioning energy management platform
Codeforces Round #770 (Div. 2) ABC
如何搭建一支搞垮公司的技术团队?
Some query constructors in laravel (2)
Action News
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
Pytorch register_ Hook (operate on gradient grad)
A tab Sina navigation bar
Lsblk command - check the disk of the system. I don't often use this command, but it's still very easy to use. Onion duck, like, collect, pay attention, wait for your arrival!
力扣剑指offer——二叉树篇