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

IXmlSerializable implementation ruins xml serialization

I have a class containing a readonly string. Thus I need to manually handle xmlserialization. But it seems that using this class in a grander setting with automatic xml...
Jon Skeet
people
quotationmark

I suspect the problem is that you're not reading to the end of the containing element - I suspect you want: public void ReadXml(XmlReader reader) { Name = reader.ReadElementContentAsString(); } The documentation for ReadXml states: ... more

people

Error in actionPerformed?

I'm trying to create a button for importing CSV file and I'm getting this error: actionPerformed(java.awt.event.ActionEvent) in cannot implement ...
Jon Skeet
people
quotationmark

Well yes - look at the declaration of the method you're implementing: void actionPerformed(ActionEvent e) It isn't declared to throw any checked exceptions. So you can't add a checked exception such as IOException with a throws clause.... more

people

Manual closing inside try with resource

Let's say I'm using a poorly documented third party library, one for which no source code is available. One of the library's methods accepts an InputStream to load various...
Jon Skeet
people
quotationmark

It will entirely depend on the implementation of the resource itself. The try-with-resource statement is "just" syntactic sugar (but oh so sweet) for calling close() within a finally block (and preserving exceptions etc). So long as the... more

people

What is the purpose of the using statement?

On the basis of what is written on this web page, and if I understand correctly, the using statement works like a try/finally, so I might mistakenly expect that if an exception...
Jon Skeet
people
quotationmark

if I understand correctly, the using statement works like a try/finally Correct. so I would expect that if an exception occurs in a using statement, it should not crash the program. Incorrect. Neither try/finally nor using... more

people

Findbugs error Bug: br is null guaranteed to be dereferenced on exception path

I need to read a properties file. I am using BufferedReader and FileReader for this purpose. I am initializing BufferedReader to null before the try section and initializing in...
Jon Skeet
people
quotationmark

How can I get rid of this error? The problem is that if the BufferedReader or FileReader constructor throws an exception, br will be null but you're still unconditionally calling br.close(). Check whether br is null before you close... more

people

Difference between Task and async

C# provides two ways of creating asynchronous methods: Method 1: static Task<string> MyAsyncTPL() { Task<string> result = PerformWork(); return...
Jon Skeet
people
quotationmark

await is basically a shorthand for the continuation, by default using the same synchronization context for the continuation. For very simple examples like yours, there's not much benefit in using await - although the wrapping and... more

people

Why default constructor cannot handle exception type Exception?

I want to know that why i have to define an explict constructor because i am getting error which says that default constructor cannot handle exception type Exception thrown by...
Jon Skeet
people
quotationmark

Yes - your Example class is effectively declaring: public Example() { super(); } That won't compile, because the super() call is calling the A() constructor which is declared to throw Exception, which is a checked exception. That's... more

people

Add object to list of same object

I got this to classes: public class NotifyUser : ContentPage { public NotifyUser() { Friends = new List<FriendStatus>(); } public string Namn { get;...
Jon Skeet
people
quotationmark

I strongly suspect that this line is the problem: var loggedinuser = RavenSession.Load<ContentPage>("NotifyUser/" + user) as NotifyUser; loggedinuser will be null if the Load method actually returns something other than a... more

people

How to cast double or double array into double array always in C#

I have method which process the double arrays. I am supplying double arrays using keyword params. My problem is sometimesI have to pass doubles as well and I want to use to same...
Jon Skeet
people
quotationmark

Now you've given an example of how you want to call it, I suspect that using dynamic typing may be the simplest approach: public void DoSomething(params object[] values) { foreach (dynamic value in values) { // Overload... more

people

Which one is Safer? Putting An "for" in a "Try" , or putting a "Try" in An "for"?

I have this piece of code, I want to know do they work likewise and only their speed is different or they act totally different? try { for (int i = Start; i < End;...
Jon Skeet
people
quotationmark

Just don't do that to start with - it's an abuse of exceptions, IMO. Write the code so it's safe without try/catch. If you don't know whether HR is long enough, use: int cappedEnd = Math.Min(HR.Length, End); for (int i = Start; i <... more

people