A common usage of catch and finally together is to obtain and use resources in a try block, deal with exceptional circumstances in a catch block, and release the resources in the finally block.
Questions tagged [try-catch-finally]
435 questions
4
votes
1 answer
Scala Continuations - Why can't my shifted call be inside a try-catch block?
I'm new to Scala continuations, and relatively new to the scala language in general.
I tried playing with Scala continuations and wrote the following code:
case class MyException(msg:String) extends Exception
def go:Int = reset {
println("enter…

Oren
- 2,767
- 3
- 25
- 37
4
votes
6 answers
Throw Exception VS Return Error within a Try,Catch,Finally
I'm pretty sure I already know the answer, but I'm still curious what the opinion is on handling an error within a Try,Catch,Finally block -- but when you're repeating yourself.
BTW - I'm not talking about User Input - but using that for an example…

hugoware
- 35,731
- 24
- 60
- 70
3
votes
4 answers
What is the point of declaring an exception rather than handling it
As far as I understand, if you only declare a checked exception it will propagate through all your methods down to the main method and still interrupt your normal program flow and your program will still stop working. So, why not always handle…

dido
- 3,347
- 11
- 34
- 42
3
votes
1 answer
Can't catch COMException (vb.net)
I use the following code to access a VSS item:
Dim sItem As String = "$/MyVssProject/InexistentFile.txt"
Dim oItem As SourceSafeTypeLib.VSSItem = Nothing
Try
oItem = m_oSourceSafe.VSSItem(sItem)
Catch ex As Runtime.InteropServices.COMException
…

Robin Holenweger
- 321
- 3
- 14
3
votes
2 answers
Reliability of corrupted state exception handling
I'm currently looking into reliability features and exception handling of C# / .NET
These are especially the HandleProcessCorruptedStateExceptions attribute and CER s with PrepareConstrainedRegions.
Now I was reading the reference source code of the…

ordag
- 2,497
- 5
- 26
- 35
3
votes
1 answer
Cleaning up an object only if an exception is raised
I need to have a file deleted if not all the operations that must be done on it were successful (that is, if an exception is raised). It could have been as simple as using except:, deleting the file and then re-raising the exception, but in that…

plok
- 705
- 7
- 30
3
votes
1 answer
Retrieving a task instance scheduled with ScheduledExecutorService
I got a ScheduledExecutorService for task scheduling in a JEE environment. Some of those task are leaving resources opened when they are interrupted with ScheduledExecutorService.shutdownNow() (e.g. open files with a third-party lib like Lucene).
I…

ggarciao
- 1,618
- 16
- 29
3
votes
5 answers
try-catch-finally vs abstract methods
in our system we have an abstract class, let's call it BasicAction, which contains several abstract methods. Most important of them is called execute. It handles the requests from the JSP pages. The main handler works like this:
// Sample 1:
String…

SPIRiT_1984
- 2,717
- 3
- 29
- 46
3
votes
1 answer
PowerShell Try Catch error handling function doesn't show my custom warning message
I am trying to write a simple PowerShell code to create a registry key, then use TRY and CATCH to handle/catch any potential exceptions that may occur. As a test scenario, I am expecting to get "Script failed to create the registry key" if I modify…

Mazda
- 33
- 1
- 5
3
votes
6 answers
Exception handling placement - C#
I've decided to remove some of the using statements in my code so I can catch specific exceptions and handle the disposing of resources manually. I have refactored some of the code to make it more readable and maintable, after implementing the new…

Jamie Keeling
- 9,806
- 17
- 65
- 102
3
votes
4 answers
Point of try catch finally blocks?
What is the difference between using finally
void ReadFile(int index)
{
// To run this code, substitute a valid path from your local machine
string path = @"c:\users\public\test.txt";
System.IO.StreamReader file = new…

bevacqua
- 47,502
- 56
- 171
- 285
3
votes
1 answer
Android: How to check IOException cause when drive is out of space
How to check IOException cause on the catch?
Is e.getCause().getMessage() always returns the same string on all the android versions and devices for the same cause? Is it a good approach to check if IOException's cause is…

Eftekhari
- 1,001
- 1
- 19
- 37
3
votes
3 answers
Try Catch Errors many script components - JavaScript
I have a page that contains many script components (50+) and I am getting an error when using IE at some random instance (doesn't happen in Chrome or Firefox).
"Out of Memory at line: 1"
I've done some google search too and that reveals issues…

Neophile
- 5,660
- 14
- 61
- 107
3
votes
1 answer
Exception thrown in finally and catch block
have question on exception thrown in catch and finally block:
class MyExc1 extends Exception {}
class MyExc2 extends Exception {}
class MyExc3 extends MyExc2 {}
public class C1 {
public static void main(String[] args) throws Exception {
…

Vijaya Raghavan
- 111
- 4
3
votes
1 answer
What happens when both catch block and finally block throw exception in Java?
Consider this question I was asked in an interview
public class Test_finally {
private static int run(int input) {
int result = 0;
try {
result = 3 / input;
} catch (Exception e) {
…

user18424
- 401
- 1
- 3
- 8