exception

how to handle db exception in c#

Hi, my question is how to handle sql exception in c#, is there anyway to check what kind of the sql exception throws from data access layer? For example, if db throws an unique constraint exception, or foreign key exception, is there any way to catch it from c#? what's the exception handling pattern you are using for these db exception? ...

Why do I get InvalidCastException when casting a double to decimal

I'm trying to debug an application which gets an InvalidCastException. The failing line is decimal d = (decimal)row[denominator]; inspecting this in the debugger(see screenshot below), row[denominator] holds a double with value 8.0 as far as I can tell. Surly there shouldn't be any problem casting that to a decimal ? (The 'row' type...

Configuring Grails to mail all exceptions generated in the production environment

Question: How do I configure Grails to send an e-mail with all log4j error messages (including exceptions) generated in the production environment? Worth noting: This question pertains to Grails 1.1, the solution for Grails 1.0 is described here. ...

What happens when a .NET thread throws an exception?

We have an interface IPoller for which we have various implementations. We have a process that will take an IPoller and start it in a separate thread. I'm trying to come up with a generic way of providing exception handling for any IPollers which don't do it themselves. My original thinking was to create an implementation of IPoller t...

window.toString.call is undefined in IE8

When you run: window.toString.call("") everything's fine in FF/CH but in IE8 you get a script error. Investigating a bit more it turned out, that window.toString.call is undefined in IE8? You can also run this one: window.toString instanceof Function; // false alert(window.toString); // function toString() { // [native code] // ...

Should I inherit from std::exception?

I've seen at least one reliable source (a C++ class I took) recommend that application-specific exception classes in C++ should inherit from std::exception. I'm not clear on the benefits of this approach. In C# the reasons for inheriting from ApplicationException are clear: you get a handful of useful methods, properties and constructor...

One reader, many writers

Related: How to catch exceptions from a ThreadPool.QueueUserWorkItem? I am catching exceptions in background threads started by ThreadPool.QueueUserWorkItem(), and propagating them to the main thread via a shared instance variable. The background threads do this: try { ... stuff happens here... } catch (Exception ex1) { lock...

Using handled exceptions as an intended trigger?

Occasionally in my code I will intentionally use a thrown exception as an event trigger. For instance, I will loop UNTIL an exception is thrown and then break; in the catch clause. Is this bad practice? Would it be more efficient (or cleaner) to query some attribute of what I am looping to predetermine the indices (i.e. predetermine w...

Why does SerializationInfo not have TryGetValue methods?

When implementing the ISerializable interface in C#, we provide a constructor which takes a SerializationInfo object, and then queries it with various GetInt32, GetObject etc. methods in order to fill the fields of the object which we are trying to deserialize. One major reason to implement this interface, rather than just using the [S...

LinQ to SQL : InvalidOperationException in a Windows Service

Hi all, I have implemented a small Windows Service which runs every 9 minutes and writes the data which comes througth a webservice to the db. Do do the db work I use Linq To SQL using (var db = new DataClasses1DataContext()) { var currentWeather = this.GetWeatherData(); //////TODO Add the ...

Problem in ASP.NET to throw an error and catch it in the global.asax

Hi, In an aspx web page I'm doing this: Try Throw new IndexOutOfRangeException Catch ex As Exception Dim myException As New bizException(ex) Throw myException End Try In the global.asax I'm doing this: Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) Dim myException As bizException = DirectCa...

Who deletes the memory allocated during a "new" operation which has exception in constructor

I really can't believe I couldn't find a clear answer to this... How do you free the memory allocated after a C++ class constructor throws an exception, in the case where it's initialised using the "new" operator. E.g.: class Blah { public: Blah() { throw "oops"; } }; void main() { Blah* b = NULL; try { b = new Bla...

PrintWriter exception: String index out of range.

I'm trying to read a file then append some text to a certain place in the file (ie. @ offset jabjab). The problem occurs when i'm trying to write to the file at offset jabjab. what's the error? File contents: Mi <?xml Version="1.0"?> _ File f = new File("data.dat"); String brstring = null; String entrystring = null; try ...

Unit Test for Exceptions Message

Is there a simple (Attribute-driven) way to have the following test fail on the message of the exception. [TestMethod()] [ExpectedException(typeof(ArgumentException))] public void ExceptionTestTest() { throw new ArgumentException("BBB"); } I would Like to have the test pass if the message in the exception is BBB , but fail if it i...

Disable "Foo has encountered a problem and needs to close" window

Is there a way (other than WerAddExcludedApplication which won't work in Windows XP) to disable the window "Application has encountered a problem and needs to close" from appearing when my application crashes? (image taken from Bil Simser' blog) I need this to work in Windows XP. ...

Custom exception handling in Python

I have two modules, main and notmain. I declared my custom exception in main module and want to catch it. This exception is raised in notmain module. The problem is I can't catch my exception raised in notmain module. main.py: class MyException(Exception): pass m = __import__('notmain') try: m.func() except MyException as e: ...

Global exception handler for windows services?

Is there a way to globally handle exceptions for a Windows Service? Something similar to the following in Windows Forms applications: Application.ThreadException += new ThreadExceptionEventHandler(new ThreadExceptionHandler().ApplicationThreadException); ...

exception in Linq to sql

my query is : var ReadAndUnreadMessages = (from m in MDB.Messages orderby m.Date descending where m.ID_Receive == (Guid)USER.ProviderUserKey && m.Delete_Admin == false select new AllMessages() { id = (LoadMessageChildren(m.ID_Message)[LoadMessageChildren(m.ID_Message).Count - 1] a...

How do I get the exception to come up at the source of the exception and not the point I call Invoke?

I have written a command manager that uses reflection to make calls to various methods and it works wonderfully except that when an exception happens in one of the handlers the break into debugging happens in the command manager and not at the point the exception was originally thrown. Is there a way to get it to break into the exception...

C++: watch a memory location/install 'data breakpoint' from code?

Hi everyone We have a memory overwrite problem. At some point, during the course of our program, a memory location is being overwritten and causing our program to crash. the problem happens only in release mode. when in debug, all is well. that is a classic C/C++ bug, and a very hard one to locate. I wondered if there's a way to add s...