Computer Science Canada What is the recommended way of handling exceptions? |
Author: | BigBear [ Mon Jan 14, 2013 4:37 pm ] | ||||
Post subject: | What is the recommended way of handling exceptions? | ||||
If you are executing multiple statements in a row that can throw an exception should you use two try-catch blocks or one and handle the exception from each line separably. Option #1
Or option #1
|
Author: | Tony [ Mon Jan 14, 2013 5:03 pm ] |
Post subject: | RE:What is the recommended way of handling exceptions? |
This largely depends if you want "anotherthing" to be attempted or not, given that "onething" is throwing an exception. |
Author: | wtd [ Mon Jan 14, 2013 10:24 pm ] |
Post subject: | RE:What is the recommended way of handling exceptions? |
There's no right answer. A lot of it comes down to how it "feels." For me, the question is whether onething and anotherthing are related. If so, then they should probably be in the same try block. |
Author: | BigBear [ Tue Jan 15, 2013 11:20 am ] |
Post subject: | RE:What is the recommended way of handling exceptions? |
Is it recommended to have the exception type even if you just abort and don't use it? |
Author: | Tony [ Tue Jan 15, 2013 1:08 pm ] |
Post subject: | RE:What is the recommended way of handling exceptions? |
It is recommended to have the exception type so that you are catching only the expected exceptions. Should things truly go wrong, you'd want to know about this. |