exception

C++: Cross thread exception handling problem with boost::exception

Basically, I've got a situation where one thread throws an exception which a different thread needs to handle. I'm trying to do this with boost exception, however somewhere along the line the exception loses its type and thus isn't caught by the catch blocks. Basically, thread B wants to do something, however for various reasons it mus...

Exceptions on .Net ThreadPool Threads

Duplicate: How to catch exceptions from a ThreadPool.QueueUserWorkItem? I am queueing up multiple delegates on the .Net ThreadPool for a large number of independant remoting calls that themselves call multiple databases and other offline resources. By Queueing these calls on the ThreadPool I can run them concurrently and minimize th...

Compilation failed: throw an exception or do not?

I'm writing .NET On-the-Fly compiler for CLR scripting. And have a dilemma: is it better to throw an exception on build fail or not? So what is the best-practice point of view, which approach is more suitable? try { compiler.Compile(); // do not throws an exception only if build succeed } catch(CompilerException ex) { string err = ...

In my application, why does readInt() always throw an EOFException?

(Forgive me because I do not write in Java very often.) I'm writing a client-side network application in Java and I'm having an interesting issue. Every call to readInt() throws an EOFException. The variable is of type DataInputStream (initialized as: DataInputStream din = new DataInputStream(new BufferedInputStream(sock.getInputStream(...

Displaying friendly error messages

I'm curious if anyone has given some thought to the wording in desktop application error messages. As a developer I always put on my programmer hat and display it in a dialect that looks like a robot is speaking to the user. For example: Failed to open file _ Unable to retrieve settings file Error occurred updating the database Cannot...

Exception when trying to deserialize a xml file

Im trying to deserialize an XML file with XmlSerializer, however im getting this exception: "There is an error in XML document (1, 2)" The innerexception is: "<Mymessage xmlns='http://MyMessages/'&gt; was not expected." Which is the very first line in the XML file. my guess is that it has something to do with the xmlns. I...

Throwing a Win32Exception

I've been writing a lot of code recently that involves interop with the Win32 API and have been starting to wonder what's the best way to deal with native (unmanaged) errors that are caused by calls to Windows API functions. Currently, the calls to native functions look something like this: // NativeFunction returns true when successfu...

Exceptions vs Special return values

Which one is a better practice in programming? I am not talking about complete exclusivity. It's more for things like: list<T>.Find, where you get default(T) or your value, instead of ValueNotFound exception (example). or list<T>.IndexOf, where you get -1 or the correct index. ...

How to catch an exception thrown by a filter in .NET's MVC?

One of the filters on an application I'm developing checks to see if a user owns the item they are trying to alter. The action is decorated by the [RequiresOwnership] attribute, and inside the attribute logic, I check to see if the user owns the item, and if they don't, I throw an UnauthorizedAccessException. My question is this: Where ...

Should I use AppDomain.CurrentDomain.BaseDirectory or System.Environment.CurrentDirectory?

I have two exe files in the same folder, I can run exe2 from a button in exe1. Today I was observing a customer over a remote (terminal services) session and exe2 failed to run 'File not found' error, yet exe1 was in the same directort when we checked. So should I be using AppDomain.CurrentDomain.BaseDirectory or System.Environment.Curre...

SQLCommand.ExecuteScalar() - why it throws a System.NullReferenceException?

Hi, Could anyone notice what could be wrong with the following function: public string Login(string username, string password) { string result = ""; string select = "SELECT user_id FROM [user] WHERE username = @username AND password = @password"; SqlConnection conn = new SqlConnection(connectionString); ...

Image.FromStream() method returns Invalid Argument exception

Hello, I am capturing images from a smart camera imager and receiving the byte array from the camera through socket programming (.NET application is the client, camera is the server). The problem is that i get System.InvalidArgument exception at runtime. private Image byteArrayToImage(byte[] byteArray) { if(byteArray != null) { ...

Uploading files to server

I am trying to upload a file from my Windows application to the server into a particular Folder using C#. However, I am getting an exception: "An exception occurred during a WebClient request". Here is my code: for (int i = 0; i < dtResponseAttach.Rows.Count; i++) { string filePath = dtResponseAttach.Rows[i]["Response"]; WebC...

Java -- Exception must be thrown, but how?

I am getting an error in NetBeans saying I must throw an SQLException in this method: private void displayCustomerInfo(java.awt.event.ActionEvent evt) { int custID = Integer.parseInt(customerID.getText()); String info = getCustomerInfo(custID); re...

How to best execute a set of methods even if an exception happens

In a current Java project we have code similar to the following example: try { doSomeThing(anObject); } catch (SameException e) { // Do nothing or log, but don't abort current method. } try { doOtherThing(anObject); } catch (SameException e) { // Do nothing or log, but don't abort current method. } // ... some more cal...

A First Chance Exception

Good evening, everyone; My name is Braden and I'm using Visual Basic 2008 Express Edition. I've been running through the MSDN help documents to get a hang of Visual Basic. After trying out the example using timers --one drags a label and timer component into the designer and adds the following to the components subroutine Label1.Text...

C# Correct paramName for ArgumentException in Property Setter

If an invalid value is passed to a property setter and an ArgumentException-ish exception is thrown, what should be passed as paramName? "value", since it seemingly is the actual argument? Wouldn't it be more clear to pass the name of the propery instead? ...

Why does Visual Studio displays some of my exceptions on the following line instead of the faulting line?

The usual behaviour of VS is to display in yellow the faulting line : int i = 1; switch (i) { default: throw new NotImplementedException(); //this will be yellow } However, quite frequently, I've witnessed that the wrong line is coloured, like in this example : int i = 1; switch (i)...

How do I find out what originally caused an exception, if it gets thrown from Microsoft's code?

I have two controls containing DataGridViews on different panes in a DockPanel. If one is in edit mode and I switch pane, I get a NullReferenceException thrown from within the DataGridView's EndEdit() method. The stack trace doesn't go any deeper than that and the exception doesn't contain any more information. I've looked at that met...

Word Automation InvalidCastException RPC / COM Exception

Hello I'm developing word automation application and I'm facing serious issue with unexpected RPC/COM cast exception [System.InvalidCastException: Nie można rzutować obiektu modelu COM typu 'System.__ComObject' na typ interfejsu 'Microsoft.Office.Interop.Word._Application'. Ta operacja nie powiodła się, ponieważ wywołanie...