You searched for exceptions. We found 168 results in 0.175 seconds.

Unreported exception java

I am getting an unreported exception; must be caught or declared to be thrown error in the fill method below. From similar posts I read I am assuming that the error originates...
Jon Skeet
people
quotationmark

Your fillData calls buffer.readLine(), which is declared to throw IOException - but you neither catch the exception witin fillData, nor declare that it might be thrown. The simplest fix is to change the signature of fillData to: public... more

people

Difference between .NETs using Statement and Javas try with ressources

I learned C# in school and now I started to learn Java. In Java there is "try with ressources" which will close/dispose stuff (like a Scanner) when it's not used anymore. The...
Jon Skeet
people
quotationmark

No, they're not exactly the same. try-with-resources statements can declare multiple variables of different types; using statements can declare multiple variables, but they all have to be of the same type A using statement doesn't have... more

people

error while returning byte array

I am using the below code public byte[] encrypt(byte[] unencryptedString,String k)throws Exception { String encryptedString = null; String k1 = String.format("%024d",...
Jon Skeet
people
quotationmark

Contrary to the other answers, I wouldn't change your code to return null if you fail to encrypt the text - I would let that failure bubble up as an exception. I wouldn't declare that your method can throw Exception either - I'd specify... more

people

JDK 1.7 onwards, throwing an exception object from catch block does not require a throws clause!!! Why is this so?

I came across a weird scenario in java today while coding around. I have a try..catch block in my method which does not have any throws clause and I am able to throw the exception...
Jon Skeet
people
quotationmark

You'll see this if the code in the try block can't throw any checked exception. At that point, the compiler knows that the only kind of exception caught by the catch block has to be an unchecked exception, and so it can therefore be... more

people

Type mismatch convert char[] to an object

I'm sure I'm missing something simple but this problem seems absolutely stupid. private static void method501(char ac[]) { char ac1[] = ac.clone(); } My problem is that the...
Jon Skeet
people
quotationmark

This happens in Eclipse if you've got your compiler settings to target very old source compatibility. With a compatibility level of 1.5 or above, it's fine - but if you set the source compatibility level to 1.3 or 1.4, you'll get this... more

people

Java buffered Read

I am working on a program for myself that shows all of the different ways to read in a text file. I have used FileWriter and BufferedWriter. My question here is why does the...
Jon Skeet
people
quotationmark

My question here is why does the FileWriter variable need to be wrapped in a BufferedWriter. It doesn't have to be - but you may well get better performance if you do, so that you avoid going to disk as often. Also, you're using... more

people

FileWriter stops unexpectedly

I am trying to use XLS2CSV to convert an Excel file to a csv text file. I modified the existing class slightly to change PrintStream to Writer so I could write to a file using...
Jon Skeet
people
quotationmark

You're not closing the writer, which means there's data still in the buffer. You should close it (and all the other streams etc) in finally blocks, or use a try-with-resources statement if you're using Java 7. Also note that the way... more

people

continue on assert

Is there any way to continue test after Assert? .. I need to see all cases which the assert causes. foreach (var ex in data) { Assert.AreEqual(ex1, ex, msg); }
Jon Skeet
people
quotationmark

No, you can't - Assert will throw an exception if it fails, and you can't just keep going after the exception. You could catch the exceptions, and then add them into a collection... but it's not terribly nice. If you're trying to... more

people

Is it advisable to use MethodBase to find the method names for logging purposes?

I have the following code in almost every function in my source code. string methodName = MethodBase.GetCurrentMethod().Name; My question is Is it recommended to use the above...
Jon Skeet
people
quotationmark

No, I wouldn't do this everywhere in your source code. Firstly, I'd use a dedicated logging package which may have cunning ways of doing a better job, and will certainly be less obtrusive in your source code. There are various options... more

people

Async and Visual Studio failure handling

From MSDN: If the method that the async keyword modifies doesn't contain an await expression or statement, the method executes synchronously. In VSPackage I have 2...
Jon Skeet
people
quotationmark

the second command seems to do nothing. What is the reason? The second method is asynchronous, which means exceptions are never thrown directly to the caller - whether the exception occurs while the method is executing synchronously... more

people