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

What happens when you await a synchronous method

If I have a synchronous method "GetStrings()": private static Task<string[]> GetStrings(IEnumerable<int> ids) { var tasks = ids.Distinct().Select(GetString); ...
Jon Skeet
people
quotationmark

Task.WhenAll doesn't block anyway, unlike Task.WaitAll. It just return a task that completes when all of the original tasks have completed. It's important to understand that you don't await a method - you await a value (or some type that... more

people

Though variables have been initialized I get might not have been initialized error

I am having problem with the following code in an android app that I am developing. Now even though I have initialized the variables I am getting the error variable might not have...
Jon Skeet
people
quotationmark

Now even though I have initialized the variables You haven't though - not necessarily. Suppose the new SimpleSpkDetSystem(...) call throws an AlizeException. You're catching that exception and continuing - but you won't have assigned... more

people

SimpleDateFormat try parse, avoid empty catch block

I implemented the following method that can be used to convert a String to an accepted format: public static Date parseDate(final String dateString, final String[]...
Jon Skeet
people
quotationmark

You can use the overload of parse which takes a ParsePosition: public static Date parseDate(final String dateString, final String[] acceptedFormats) { ParsePosition position = new ParsePosition(0); for (String format :... more

people

java.lang.ClassCastException at runtime or compile time

I've just read in an OCA-Book (Oracle Certified Associate), that: "Some casts exceptions can be detected as errors at compile-time, but others can only be detected at...
Jon Skeet
people
quotationmark

Or does the compiler knows only the type of the reference, not of the object (in the memory) itselfs? It only knows the type of the expression that you're trying to cast. That expression is of type Object, so it's fine to cast it to C... more

people

Get the actual value that failed the Parse

Disclaimer This question is about, If and How we can use the Parse method exceptions, to find which argument/variable had actually failed the conversion. It is NOT, to argue if...
Jon Skeet
people
quotationmark

Not reliably - there's nothing in the FormatException that does this for you. Parsing the message is very fragile - it can change in different versions of .NET, and it'll be localized. One option would be to write your own Parse method... more

people

System.Threading.ThreadAbortException occurred in mscorlib.dll occuring persitently

Im new to .net, Im using the following code to transfer from gridview to excel: protected void toexcelbutton_Click(object sender, EventArgs e) { ...
Jon Skeet
people
quotationmark

Yes, it will happen due to this: Response.End(); As documented: To mimic the behavior of the End method in ASP, this method tries to raise a [ThreadAbortException] exception. If this attempt is successful, the calling thread will be... more

people

Why are Java Timer threads disappearing?

I have code that schedules one-time tasks to execute and does this over and over. It looks something like this. public static void main(String[] args) { while(true) { ...
Jon Skeet
people
quotationmark

You're creating a Timer instance, but not making sure that it doesn't get garbage collected. From the documentation: After the last live reference to a Timer object goes away and all outstanding tasks have completed execution, the... more

people

PrintStream doesn't print correctly unicode characters ( UTF 16)

I want to print correctly unicode (let's say greek characters ) but I have problems. For example : PrintStream oStream = new PrintStream(client.getOutputStream(), true,...
Jon Skeet
people
quotationmark

This is quite possibly the issue: oStream.write(" Customer : Γειά σου\r\n".getBytes()); oStream.write(" ΚΩΔΙΚΟΣ : 00000234242\r\n".getBytes()); You're calling String.getBytes() with no encoding, to get a byte array using the... more

people

Can I set Eclipse to ignore "Unhandled exception type"

Is it possible to get Eclipse to ignore the error "Unhandled exception type"? In my specific case, the reason being that I have already checked if the file exists. Thus I see no...
Jon Skeet
people
quotationmark

Is it possible to get Eclipse to ignore the error "Unhandled exception type FileNotFoundException". No. That would be invalid Java, and Eclipse doesn't let you change the rules of the language. (You can sometimes try to run code which... more

people

Refactor class to avoid writing same pattern in every method

I have a class with a lot of static methods for managing database operations. All methods follow this pattern: try { using(var trans = new TransactionScope()) { ...
Jon Skeet
people
quotationmark

It sounds like you should pass "method body" in as a delegate: public void GiveMeAProperName(Action<DBContext> databaseAction) { try { using(var trans = new TransactionScope()) { using(var context =... more

people