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

While Collections.shuffle() doesn't throw ConcurrentModificationException

I'm actually learning collections and exceptions and I can't understand why this works : List<Integer> intList = new...
Jon Skeet
people
quotationmark

The answer lies in the documentation - emphasis mine: (A structural modification is any operation that adds or deletes one or more elements, or explicitly resizes the backing array; merely setting the value of an element is not a... more

people

Strange behavior of EOFException

I have some simple class that is DataInputStream stream to read from file. I have surrounded this stream with EOFException try-catch block. It has some strange behavior coz...
Jon Skeet
people
quotationmark

Well, you're getting an EOFException because you're reading forever - you never change the value of done. The reason it's appearing in the middle of the text instead of at the end is that you're using System.err to print in the... more

people

Storing a reference to the object in ArrayList

Hey everyone i am trying to store the current reference to an arraylist "pl". e.g. pl.add(this); for some reason i only get the reference to the last item and none of the...
Jon Skeet
people
quotationmark

This is the problem: pl.add(this); You're adding the same reference (this) again and again. The value of this is just a reference to the "current" object - and you're modifying the contents of that object in the loop. In each iteration... more

people

Unable to cast object of type 'System.Int32' to type 'System.Reflection.RuntimePropertyInfo'

I have several entities that I'd like to transform. Here is an example: public class FromClass { public string Id { get; set; } public string Name { get; set; } ...
Jon Skeet
people
quotationmark

This line is the problem: var generic = methodInfo.MakeGenericMethod(toProp.GetType()); You're calling GetType() on toProp - that will return some type derived from PropertyInfo. You actually want the property type, so just change it... more

people

Pattern to replace nested conditionals with guard clauses while still performing some action for the vast majority of cases but not all

I've got a method that kind follows the following pattern: void myMethod(String arg1) { SomeObject foo = getSomeObject(arg1); if(foo != null) { SomeOtherObject bar =...
Jon Skeet
people
quotationmark

One option would be to wrap all but the doNormalThing method call in another method that returns whether or not to execute doNormalThing afterwards: void myMethod(String arg1) { if (myMethodInternal(arg1)) { doNormalThing(); ... more

people

Does Null Object Pattern occupy memory

I've been reading that the null object pattern will help you to avoid the null checks and null pointer exceptions making your code cleaner to understand. I have never used it and...
Jon Skeet
people
quotationmark

Typically null objects aren't created on demand - instead, they're shared. They're typically immutable implementations of some other abstraction (with no-op methods or whatever is suitable) - so they can be shared very easily. At that... more

people

Crazy behavior in loop c# wpf

I have a really strange behavior in one of my view models. First, in this directory I have three csv files. When I start debugging first it goes inside the foreach and then it...
Jon Skeet
people
quotationmark

Okay, I think I see at least one potential problem (and definitely code to be avoided)... Every time you evaluate the AllDatabases property, you add all the files to the collection. Property fetches shouldn't do that - they shouldn't... more

people

Concurrent execution of async methods

Using the async/await model, I have a method which makes 3 different calls to a web service and then returns the union of the results. var result1 = await...
Jon Skeet
people
quotationmark

How would I go about letting them execute in parallel and join the results as they complete? The simplest approach is just to create all the tasks and then await them: var task1 = myService.GetData(source1); var task2 =... more

people

Java PrintWriter Save File to Source Package in NetBenas

I am using the following java code in NetBeans to read and write to a file. import java.io.*; import java.util.*; public class FileReadWrite { StringTokenizer tokenizer; ...
Jon Skeet
people
quotationmark

If you want to be able to save the scores again, using getResourceAsStream isn't really a good idea - that's meant for resources which are bundled with the application, often within a jar file, and often read-only. You might want to... more

people

Why last array filled with first array without asking?

I try to hold some value in 1st array, then another value in 2nd array, I try to print 1st array and it returns 2nd array values. Any ideas why ? this is main method to call...
Jon Skeet
people
quotationmark

You're only actually populating a single array - and overwriting it every time you call getCol. So the values of cola1 and cola2 end up referring to the same array, whereas you want them to refer to different arrays. You should probably... more

people