exception

throwing an exception in a windows service

Hi, Does throwing an exception in a windows service crash the service? i.e. it will have to be restarted manually Note: I am throwing the exception from within the catch clause. ...

Exception with WCF

Whats the best way handle exception from a WCF service? How can you throw the exception from a WCF service? ...

Avoid exceptions?

This particular example relates to Django in Python, but should apply to any language supporting exceptions: try: object = ModelClass.objects.get(search=value) except DoesNotExist: pass if object: # do stuff The Django model class provides a simple method get which allows me to search for one and only one object from the ...

Best practices for exception management in JAVA or C#

I'm stuck deciding how to handle exceptions in my application. Much if my issues with exceptions comes from 1) accessing data via a remote service or 2) deserializing a JSON object. Unfortunately I can't guarantee success for either of these tasks (cut network connection, malformed JSON object that is out of my control). As a result,...

Exception vs Assert?

Is there a rule of thumb to follow when deciding to use exceptions instead of asserts (or vice versa). Right now I do only throw if its something I think will happen during runtime on the user side (like a socket or file error). Almost everything else I use asserts. Also, if I were to throw an assert, what is a nice standard object to t...

Why are Exceptions said to be so bad for Input Validation?

I understand that "Exceptions are for exceptional cases" [a], but besides just being repeated over and over again, I've never found an actual reason for this fact. Being that they halt execution, it makes sense that you wouldn't want them for plain conditional logic, but why not input validation? Say you were to loop through a group of...

NotImplementedException - are they kidding me?

This really, really urks me, so I hope that someone can give me a reasonable justification for why things are as they are. NotImplementedException. You are pulling my leg, right? No, I'm not going to take the cheap stab at this by saying, "hang on, the method is implemented - it throws a NotImplementedException." Yes, that's right, y...

Is Try-Finally to be used used sparingly for the same reasons as Try-Catch?

I just finished reading this article on the advantages and disadvantages of exceptions and I agree with the sentiment that Try-Catch blocks should not be used for "normal" control-flow management (don't use them like a goto). However, one author made (good) points about Maintainability and especially Performance that made me wonder abou...

dlopen on library with static member that throws exception in constructor - results in Abort

I am trying to load a dynamic library using dlopen function. This library contains a static object, which throws an exception in its constructor. I have a "try-catch(...)" block around the dlopen call, but it doesn't catch the exception, and I just see "Abort" printed. How am I able to catch this exception? ...

Propagating C++ exceptions across C stack frames on OS X

Hello everyone, The application I'm working on (it's a game, actually) uses XML for some of its configuration. Since I'm using CEGUI for the GUI, and it has its own XML parsing objects, I converted my code to use that instead of my own hand-rolled parser class. If the document is missing attributes on certain tags, it throws an except...

When to use assertion over exceptions in domain classes

Are there any situations when you would use assertion instead of exceptions-handling inside domain classes... ...

Which contract (Design by contract) is better?

Suppose I have a method public Patient(int id) { ---- } that returns Patient object given an id.. I could define contract in 2 ways Method would return null if patient does not exist Method would throw an exception if patient does not exist. In this case I would also define a query method that returns true if the Patient exist i...

.NET: Which Exception to Throw When a Required Configuration Setting is Missing?

Here's a standard scenario: if(string.IsNullOrEmpty(Configuration.AppSettings("foobar"))) throw new SomeStandardException("Application not configured correctly, bozo."); The problem is, I am not entirely certain which exception SomeStandardException should be. I perused the 3.5 Framework and found two likely candidates: Configura...

Why Create Custom Exceptions?

Why do we need to create custom exceptions in .NET? ...

Are assertions always bad?

I used to work for a company where some of the lead architect/developers had mandated on various projects that assertions were not to be used, and they would routinely be removed from code and replaced with exceptions. I feel they are extremely important in writing correct code. Can anyone suggest how such a mandate could be justified?...

Exception refuses to be handled.

I tried two ways of catching unexpected unhandled exceptions: static void Main() { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(ErrorHandler.HandleException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(f...

Thread was being aborted when exporting to excel?

I have a DataTable which is bound to a GridView. I also have a button that when clicked exports the DataTable to an Excel file. However, the following error is occuring: ErrMsg = "Thread was being aborted." Here is part of the code where the error is being thrown: private static void Export_with_XSLT_Web(DataSet dsExport, ...

Java Style: Properly handling exceptions.

I keep getting stuck conceptually on deciding an Exception-handling structure for my project. Suppose you have, as an example: public abstract class Data { public abstract String read(); } And two subclasses FileData, which reads your data from some specified file, and StaticData, which just returns some pre-defined constant data....

Is this a bad practice to catch a non-specific exception such as System.Exception? Why?

I am currently doing a code review and the following code made me jump. I see multiple issues with this code. Do you agree with me? If so, how do I explain to my colleague that this is wrong (stubborn type...)? Catch a generic exception (Exception ex) The use of "if (ex is something)" instead of having another catch block We eat SoapEx...

Winforms unceremoniously quits with "unhandled exception"

The program spits up one of those boxes saying an unhandled exception has occurred and the application must quit. The only clue I get to solve the problem is this in the event log: Event Type: Error Event Source: .NET Runtime 2.0 Error Reporting Event Category: None Event ID: 5000 Date: 1/9/2009 Time: 8:47:44 AM User: N/...