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

Unexacte parsing in SimpleDateFormat

How to parse a string with always different formats of date (sometimes "yyyy-MM-dd HH:mm:ss", or "yyyy-MM-dd'T'HH:mm" or also "yyyy-MM-dd HH:mm")? If I use the following code -...
Jon Skeet
people
quotationmark

I would suggest you just try to parse each specific format, catching ParseException and just moving onto the next format: private static final String[] patterns = { "yyyy-MM-dd HH:mm", "yyyy-MM-dd'T'HH:mm", "yyyy-MM-dd... more

people

DLL out int not accepted

I have built a DLL in C#. In the following function the IDE tells my that the function _api.Version has some invalid arguments. But I don't think that this is true. public...
Jon Skeet
people
quotationmark

In C#, you need to specify out and ref modifiers at the call site as well as in the member declaration. That means that anyone reading the code is aware of what is going on. (This is a big boost to readability, in my view.) So you... more

people

Representing signed byte in an unsigned byte variable

I apologies if the title of this question is not clear, but i cannot figure out the best way to describe my predicament in so few words. I am writing a communication framework...
Jon Skeet
people
quotationmark

You basically don't need to do anything except stop thinking about bytes as numbers. Think of them as 8 bits, and Java and C# are identical. It's rare that you really want to consider a byte as a magnitude - it's usually just binary data... more

people

Reading a file using fixed number of bytes java

I am writing a program to copy large files, so I want to read specific number of bytes and write to another file. I want to copy the file and get same number of bytes. But I am...
Jon Skeet
people
quotationmark

There are several problems with your code: You're using the default platform encoding to convert the binary data into text (by calling new String(byte[]) instead of specifying an encoding You're using the default platform encoding to... more

people

Generating fatal error in Java

Suppose we are writing a Java library, which provides some I/O ulitity functions, for example, a convenient method to read text files as Strings: public class StringReader...
Jon Skeet
people
quotationmark

But what if it doesn't? Then you're in a really bad situation, and you should probably get out of it as quickly as possible. When a JRE is violating its own promises, what would you want to depend on? I'd feel happy using... more

people

Can I create a generic method that takes a value type or a reference type but always returns a nullable type

This is my method. Note that I am returning the equivalent nullable type for the generic parameter R: public static Nullable<R> GetValue<T, R>(this T a,...
Jon Skeet
people
quotationmark

No, there's no individual signature that can do this - there's no way of saying "the nullable type of R, which is either R itself for a reference type, or Nullable<R> for a non-nullable value type". You can have different methods,... more

people

Return results from executor in java

I need some help retrieving results from executors. The place where I create the workers: public static void method() { double bestProb = 0; double best p1 =...
Jon Skeet
people
quotationmark

(This answer was provided when the question was at revision 1. The OP is editing the question in response to the answer, which makes the answer make less sense - rather than me try to keep up with the edits, please refer to revision 1 to... more

people

How to parse an xml file and return default value if no element found

I wrote a simple method in C# to parse a given xml file and return the value of a specific node. It works fine but I'd also like to return a default value if the node is not found...
Jon Skeet
people
quotationmark

Let's start by getting rid of the exception "handling". The node not being found is a "reasonable to expect" error, and one we're going to ensure doesn't result in an exception. Other exceptions - such as the file not being found at all,... more

people