Question, shouldn't try catch be used at the beginning of writing your code and after that you clean it up, because you know now that the code is stable?
I'm not sure I fully understand what you are saying.
It sounds like you're saying you wrap the full app startup in a try catch and then come along later and remove it?
Try catches should be wrapped around any method you expect can throw an error at the layer you wish to handle it.
Perhaps you have three layers:
UI
Business
Data Layer
Your data layer may throw and error but you want to catch it at the UI level so you can show an error to the user.
Or perhaps, your business layer throws an error, but you want to catch it immediately so you can call a fallback method etc.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Question, shouldn't try catch be used at the beginning of writing your code and after that you clean it up, because you know now that the code is stable?
I'm not sure I fully understand what you are saying.
It sounds like you're saying you wrap the full app startup in a try catch and then come along later and remove it?
Try catches should be wrapped around any method you expect can throw an error at the layer you wish to handle it.
Perhaps you have three layers:
UI
Business
Data Layer
Your data layer may throw and error but you want to catch it at the UI level so you can show an error to the user.
Or perhaps, your business layer throws an error, but you want to catch it immediately so you can call a fallback method etc.