exception

How to decide where to handle an exception - in scope of function it been thrown or in global one?

I`m writing client-server app for windows using WinSock and I have class for server. while initialising server I have such code: class Server { static const int MaxClients = 10; std::vector connections; CRITICAL_SECTION cs; int port; SOCKET ServerSocket; sockaddr_in ServerAddress; void init(); public: S...

SerializationException when setting instance of one class to another

I'm trying to pass an instance of a class between two separate classes, like the following. //classes public class A { public string name; public string data; } public class B : MarshalByRefObject { public A _a; } public class C : MarshalByRefObject { public A _a; } //main program static void Main(string[] args) { B _b = ...

System.Net's Webclient in C# won't connect to server.

Is there something I need to do to get System.Net working with Microsoft Visual C# 2008 Express Edition? I can't seem to get any web type controls or classes to work at all.. the below WebClient example always throws the exception "Unable to connect to the remote server".. and consequently I can't get the WebBrowser control to load a pag...

Create user exception derived from std::exception?

How a user exception class is created from standard exception? Addressing below cases Say i have a class with some enum that indicates type of object so based on type, member functions are available.Calling member function that is not available should throw an exception.Similarly when a getter of uninitialized is called again a except...

Where do you like to catch exceptions and why?

Where do you like to catch exceptions and why? I'm interested in seeing where people find it useful to put their try/catch blocks in the hope that some general patterns might emerge. I'll post my two example answers in C++ but any language is fine. One location and reason per answer please. Thanks. ...

How do I stop exceptions trashing my delegate chain?

I have come across what must be a common problem. When I have an event which may be subscribed to by several different classes, an exception thrown by one of these classes will kill the callback chain; as I do not know a priori in what order the callback is carried out, this can result in unpredictable state changes for some classes and ...

What does "Polling caught an exception, restarting polling." error mean?

We recently discovered the below error in our log which happened before our Reporting Services going down. Our servers have been very slow lately and wondering if this could be part of the problem. Error Message: "Polling caught an exception, restarting polling. Error Message System.Data.SqlClient.SqlException: Timeout expired." ...

Where is the right place parametric type checking in dynamic languages?

Consider the following. (in pseudocode). Class { hello world public constructor(hello, world) { if (hello is not String) { throw Exception() } if (world is not Array) { throw Exception() } this.setHello(hello) this.setWorld(wor...

exception hierarchy vs error enumeration

I read somewhere (can't find it now) that large exception hierarchies are a waste of time. The justification for this statement seemed sound at the time and the idea stuck with me. In my own code when I have a code base that can have a range of error conditions I use a single exception with an enumeration member to differentiate betwee...

Subquery is not supported on 'IsDeleted' of type 'Entities.Product'

I'm using Linq to SQL and trying to filter data using DataOptions and AssociateWith. I have a table called Products that has a primary key called Id and a flag called IsDeleted with sql-datatype bit. When I use the following code I get "Subquery is not supported on 'IsDeleted' of type 'Entities.Product'" exception on AssociateWith meth...

Unknown exception while deserializing using simple XML

I am deserializing data using Simple XML in Java, but i get an exception telling me: protokolsimulering.model.Terminal.<init>() This is my serializing code: public void saveSimulationState(String simulationFile) { try{ Strategy strategy = new CycleStrategy("id", "ref"); Serializer serializer = new Persister(strate...

LinqToSQL and the exception " ExecuteReader requires an open and available Connection."

Hi guys, I have a collection called dbUsers of type IQueryable These are pulled from a linqtosql database context i.e. IQueryable<Data.LinqToSQL.User> dbUsers = DBContext.Users Calling ToList on this object: IList<Data.LinqToSQL.User> users = dbUsers.ToList(); Results in an exception: ExecuteReader requires an open and available...

Catching exceptions thrown by plugin UserControl

I am writing a WinForms application that accepts dynamic user interface controls, in the form of plugins (think widgets). For this, the main function of each plugin returns a UserControl that is then added to the main form. Since my application doesn't have direct control over them, I would like to "sandbox" the plugins exception-wise s...

Generic catch for python

I have some extremely weird behavior that seems to result in silent exceptions. How can I write a general try catch where I can debug all exceptions. Something along the lines of: try: # something that fails except e: print e A bit more about the problem at hand in detail: I have a Django app that on the my comp (Ubuntu Linux...

exception logging help

I work on a rather large web site. We currently have 4 web servers and an active passive db cluster running asp.net 2.0 with C#. Currently our exception handling is not trapping the correct exception being thrown. I have heard it is because server.getlasterror() is not thread safe (note: we currently do not use server.getlasterror().getb...

Exceptions vs return codes : do we lose something (while gaining something else) ?

My question is pretty vague :o) - But here is an example : When I was writing C code, I was able to log counter's value when something failed : <...> for ( int i = 0 ; i < n ; i++ ) if ( SUCCESS != myCall()) Log( "Failure, i = %d", i ); <...> Now, using exceptions, I get this : try { <...> fo...

.Net WFC/Web service exception handling design pattern

I'm trying to come up with a simple, easy to use design pattern for error handling in a .net wcf service (specifically a silverlight enabled wcf service). If an exception gets thrown in the service method the silverlight application will see a CommunicationException stating "The remote server returned an error: NotFound ---> " and possib...

Automatically generating XML documentation for thrown exceptions in C#

In C#, it is good practice to add XML documentation to describe any exceptions that a method can throw. It is not difficult to add these for exceptions that you throw yourself. However, if I'm calling another method, and I've decided not to handle an exception thrown by this second method, there's no point in me re-writing existing docum...

Puzzling Enumerable.Cast InvalidCastException

The following throws an InvalidCastException. IEnumerable<int> list = new List<int>() { 1 }; IEnumerable<long> castedList = list.Cast<long>(); Console.WriteLine(castedList.First()); Why? I'm using Visual Studio 2008 SP1. ...

Getting the baseexception info

I'm logging errors and sending myself the exception logs! Like the following code private void ExceptionForm_Load(object sender, EventArgs e) { Type exceptionType = _exception.GetType(); txtErrorMessage.Text = _exception.ToString(); if (exceptionType == typeof(Sybase.DataWindow.DbErrorException)) ...