当前位置:网站首页>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边栏推荐
- Include rake tasks in Gems - including rake tasks in gems
- 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!
- The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
- A label colorful navigation bar
- Restful fast request 2022.2.1 release, support curl import
- Win: use PowerShell to check the strength of wireless signal
- A tab Sina navigation bar
- Win:使用组策略启用和禁用 USB 驱动器
- PHP wechat official account development
- 【附源码】基于知识图谱的智能推荐系统-Sylvie小兔
猜你喜欢
[OpenGL learning notes 8] texture
Summary and practice of knowledge map construction technology
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
The application and Optimization Practice of redis in vivo push platform is transferred to the end of metadata by
. Net starts again happy 20th birthday
STM32 series - serial port UART software pin internal pull-up or external resistance pull-up - cause problem search
[source code attached] Intelligent Recommendation System Based on knowledge map -sylvie rabbit
Introduce reflow & repaint, and how to optimize it?
He was laid off.. 39 year old Ali P9, saved 150million
如何搭建一支搞垮公司的技术团队?
随机推荐
One plus six brushes into Kali nethunter
Es uses collapsebuilder to de duplicate and return only a certain field
runc hang 导致 Kubernetes 节点 NotReady
MySQL backup and recovery + experiment
Talk about the things that must be paid attention to when interviewing programmers
[机缘参悟-38]:鬼谷子-第五飞箝篇 - 警示之一:有一种杀称为“捧杀”
phpstrom设置函数注释说明
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
I use these six code comparison tools
Yyds dry inventory swagger positioning problem ⽅ formula
Uniapp navigateto jump failure
batchnorm.py这个文件单GPU运行报错解决
Yyds dry inventory jetpack hit dependency injection framework Getting Started Guide
Codeforces Round #770 (Div. 2) ABC
RichView TRVStyle MainRVStyle
使用druid連接MySQL數據庫報類型錯誤
Missile interception -- UPC winter vacation training match
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
MATLB | multi micro grid and distributed energy trading
batchnorm. Py this file single GPU operation error solution