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

How to preserve await behavior with TaskCompletionSource.SetException?

(This is a new attempt at this question which now demonstrates the issue better.) Let's say we have a faulted task (var faultedTask = Task.Run(() => { throw new...
Jon Skeet
people
quotationmark

It turns out that await can throw AggregateException, though, which is not documented behavior. No, that's the behaviour when the first nested exception is an AggregateException. Basically, when you call... more

people

Non throwable code inside of a try/catch performance java

Will there be any negative performance implications on the following code due to methods that do not throw exceptions being inside of a try block? String user; try { user =...
Jon Skeet
people
quotationmark

Will there be any negative performance implications on the following code due to methods that do not throw exceptions being inside of a try block? No, it won't have any performance implications, but: I would generally put minimal... more

people

Java: proper design for multierror functionality

I am writing piece of code in Java, which job is to parse configuration file. It's convenient for the end-users, because they can see and fix all parsing errors at once. But it's...
Jon Skeet
people
quotationmark

Why not throw just a single InvalidConfigurationException (I wouldn't use ParsingError - aside from anything else, I wouldn't expect this to be an Error subclass) which contains information about the specific problems? That information... more

people

Should I declare an unchecked exception?

I've got a method which invokes another method like this: public void m1() { m2(10); } public void m2(int v) { if(v < 10) throw new MyException(); } public...
Jon Skeet
people
quotationmark

You can do so - and it'll show up in the Javadoc, I believe. But it won't force any callers to handle the exception, so you're still basically relying on the users (developers calling your code) to be diligent enough to check the... more

people

Difference between suppressedException and cause

I have my own exception, thrown by my class, BrowserException. It may be because some internal problem, i.e. UnsupporderEncodingException. Now I have 2 options: ...
Jon Skeet
people
quotationmark

A suppressed exception is one which would have happened if another exception hadn't occurred. I'm only aware of one case where this happens, which is with a try-with-resources statement. The JLS (14.20.3) says: Resources are closed in... more

people

C# equivalent of "value error" in Python

Is there a C# error exception for a value error? the equivalent of the python "value error" below? except ValueError as e:
Jon Skeet
people
quotationmark

Sounds like you probably want ArgumentException, or ArgumentNullException, or ArgumentOutOfRangeException depending on the precise nature. (The latter exceptions are subtypes of the first.) more

people

Async method throws exception instantly but is swallowed when async keyword is removed

I'm getting some behaviour which I cannot understand when throwing exceptions in async methods. The following code will throw an exception immediately when calling the ThrowNow...
Jon Skeet
people
quotationmark

I thought async methods run synchronously until reaching a blocking method. They do, but they're still aware that they're executing within an asynchronous method. If you throw an exception directly from an async void method, the... more

people

Does try catch share the same scoping block?

I have a try-catch sequence. try { int tryCatchVar = 0 ...other code... } catch { if (tryCatchVar != 0) return; } I declared and assigned a variable in the try...
Jon Skeet
people
quotationmark

However, because of the strong relational aspect of try-catch, I am wondering if the variable declared in try is in scope for catch? You can test this easily for yourself, but the answer is no. (Second part) Would that... more

people

Lightweigth default StreamReader reading nothing

I am in the need of a default StreamReader reading nothing without throwing any exceptions. How can I efficiently construct such an object? Edit Specifically, if I read from the...
Jon Skeet
people
quotationmark

Ideally, I would suggest using TextReader as your abstraction level - it's rarely necessary to depend on StreamReader directly, as messing around with the underlying stream is generally a bad idea anyway. If you have code that takes a... more

people

Sort list while in a loop using groupby

I have a loop with linq like this: foreach (var group in part.Profiles.Skip(ixstart). GroupBy(b => new { b.Number, b.X }). OrderBy(g =>...
Jon Skeet
people
quotationmark

I suspect it turns out to be safe because GroupBy doesn't stream results - it consumes all of the input before it returns any values. (It's lazy in that it doesn't do any work until you ask it for its first element, but then it consumes... more

people