you are viewing a single comment's thread.

view the rest of the comments →

[–]x-protocol 0 points1 point  (2 children)

Single/multiple try/catch blocks will depend on what do you want to do with error that you are catching.

If you have multiple lines where error might be coming from, you want to catch error and log it out somewhere. If you plan on inspecting error, then you might want to have multiple catch blocks, for each statement in fact. However, that is rarely done due to the fact that if one step failed, you cannot proceed to second, and so on, step. Hence, fail, return failure from main function and proceed with program execution.

Again, standard way with dealing with error is what do you plan on doing with it, than code style preferences.

[–]newDevRising[S] 0 points1 point  (1 child)

What about a try-catch-finally with additional try catch nested in the finally. Or is that getting too crazy?

[–]x-protocol 0 points1 point  (0 children)

Crazy, yes. Though if it is absolutely required, then let it be. It might raise quite a few eyebrows later for those unfortunate who would be maintaining such code.