当前位置:网站首页>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边栏推荐
- . Net starts again happy 20th birthday
- Tla+ through examples (XI) -- propositional logic and examples
- A label colorful navigation bar
- 187. Repeated DNA sequence - with unordered_ Map basic content
- The steering wheel can be turned for one and a half turns. Is there any difference between it and two turns
- MySQL regexp: Regular Expression Query
- Flutter 2.10 update details
- Incremental backup? db full
- [OpenGL learning notes 8] texture
- 如何搭建一支搞垮公司的技术团队?
猜你喜欢
Video display and hiding of imitation tudou.com
A label colorful navigation bar
JVM - when multiple threads initialize the same class, only one thread is allowed to initialize
A label making navigation bar
Exploration and Practice of Stream Batch Integration in JD
Comment mettre en place une équipe technique pour détruire l'entreprise?
Three properties that a good homomorphic encryption should satisfy
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
Li Kou Jianzhi offer -- binary tree chapter
Application and Optimization Practice of redis in vivo push platform
随机推荐
Traditional chips and AI chips
Incremental backup? db full
Stored procedure and stored function in Oracle
MATLB | multi micro grid and distributed energy trading
Tla+ through examples (XI) -- propositional logic and examples
Main window in QT application
Restful Fast Request 2022.2.1发布,支持cURL导入
Outlook: always prompt for user password
Mysql database | build master-slave instances of mysql-8.0 or above based on docker
Es uses collapsebuilder to de duplicate and return only a certain field
Practical case of SQL optimization: speed up your database
官宣!第三届云原生编程挑战赛正式启动!
Summary and practice of knowledge map construction technology
Flutter 2.10 update details
Kibana installation and configuration
STL container
Matrixone 0.2.0 is released, and the fastest SQL computing engine is coming
The MySQL team development specifications used by various factories are too detailed. It is recommended to collect them!
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!
One click generation and conversion of markdown directory to word format