2 Replies - 182 Views - Last Post: 08 February 2013 - 06:52 PM Rate Topic: -----

#1 Ap0C552  Icon User is offline

  • D.I.C Regular

Reputation: -7
  • View blog
  • Posts: 314
  • Joined: 08-December 10

Exception catch problem

Posted 08 February 2013 - 06:35 PM

I am writing some code to read from a file.

I have the file and buffered readers wrapped in a try/catch statement.

the catch portion is as follows

catch (Exception e)
		{
			  System.err.println("Error: " + e.getMessage());
		}


My problem is, is there is a runtime error occuring when I run the program, and it happening in an objects method that is called within the try/catch statement. So unfortunately whatever the error is, it is unknown to me, so diagnosing it is a real problem.

Is This A Good Question/Topic? 0
  • +

Replies To: Exception catch problem

#2 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7578
  • View blog
  • Posts: 12,746
  • Joined: 19-March 11

Re: Exception catch problem

Posted 08 February 2013 - 06:42 PM

On the whole it's a bad idea to catch Exception e. You want to catch the particular Exceptions that might be raised by a particular section of the code, and not any others. This is to prevent exactly the sort of masking that you're seeing here.

If you're looking for help with diagnosing your problem, you'll have to provide the relevant code and the error messages you're seeing. Try e.printStackTrace() instead of e.getMessage to get a more useful error output.
Was This Post Helpful? 2
  • +
  • -

#3 Ap0C552  Icon User is offline

  • D.I.C Regular

Reputation: -7
  • View blog
  • Posts: 314
  • Joined: 08-December 10

Re: Exception catch problem

Posted 08 February 2013 - 06:52 PM

Thank you for the reply.I will try e.printStackTrace().

I have fixed the problem by just replicating the problematic code separate from the file reading parts.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1