devxlogo

All-Encompassing Try

All-Encompassing Try

Question:
I was told that in order to make my program easier to read, I shoulduse try to cover all of my program, then catch every exception at the endof the program. Does this make any sense?

Answer:
You should catch exceptions where you intend to handle them. It makesno sense to catch exceptions only at the end of a program when manyexceptions are recoverable. For example, network servers need to beable to recover from network I/O errors. You can only do this if youcatch exceptions at the point of an anticipated failure point. Butyou must ensure that you take proper fault-recovery steps. Only fatal andnon-recoverable exceptions resulting in the termination of the programshould be caught at the end of the program.

See also  How to Create and Deploy QR Codes Online: A Comprehensive Guide
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist