All-Encompassing Try

All-Encompassing Try

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?

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.


Share the Post: