exception-handling

Best way for a .Net Windows service to report an error to the user

I am writing a windows service that will be doing a lot of network communication, and I need a way to notify a user (if logged on) of any exceptions/errors. I know it is bad practice to allow a service to interact with the desktop, so is there an alternative way to notify a user that an error has occurred? I am aware of event logging, bu...

Merge catch blocks with exactly the same code?

Hi I want to merge the catch blocks in the following code for code reuse reasons: try { DoSomeInputOutput(); } catch (InvalidOperationException ex) { HandleKnownException1(ex); } catch (InvalidDataException ex) { HandleKnownException1(ex); } catch (ArgumentNullException ex) { HandleKnownException1(ex); } catch (Argument...

How rethrow an exception without losing the original call stack?

The situation is as follows: Thread A catches an exception, saves the exception's data somewhere in memory (using GetExceptionInformation in the exception filter), and afterwords Thread B gets that exception information and wants to rethrow it. But the thing is, when thread B rethrows the caught exception, i'm missing the original call s...

PHPUnit Exception testing, error message messes up results output

Hi, my question regarding phpunit for testing exceptions using the command line tool. I can't seem to correctly do this, the error message of the exception just prints out, making the command line window harder to read. Below is how my code is structured and the test code. public function availableFruits($fruit) { switch($fruit) { ...

Who invented the throw/try/catch[/finally] kind of error handling?

My questions are more of historical nature than practical: Who invented it? Which language used it first (and to what extent)? What was the original idea, the underlying concept (which actual problems had to be solved these days, papers welcome) ? Is LISPs condition system the ancestor of current exception handling? ...

Exception handling with the WPF toolkit datagrid

I have searched around but have been unable to find out the recommended pattern for generic exception handling when using a control such as the wpf toolkit datagrid. As an example, at the moment I am getting unhandled exceptions caught by my shell application. This happens when a user clicks on a column header to sort it, and it is unab...

JavaScript exception handling - displaying the line number

When catching / handling exceptions in JavaScript, how can I determine what the call stack was when the exception occurred? (and also if possible what the line number was) try { // etc... } catch (ex) { // At this point here I want to be able to print out a detailed exception // message, complete with call stack, and if pos...

How to handle multiple asynchronous errors on a single page?

This is not necessarily a Flex-specific question, but I'll use Flex in my example: Scenario: We have a fairly complex MVC Flex application that uses remoting and makes several asynchronous calls on a single page. Some of the calls are: GetUserOrders GetCurrentOrder GetUserDetails If there is a network or DB error, this will throw th...

try and catch statements in java?

how can i rewrite the following method using try and catch statements instead of the throws clause in the method header: public String getInput(String filename) throws Exception { BufferedReader infile = new BufferedReader (new FileReader(filename)); String response = infile.readLine(); infile.close(); return response: ...

Programmatically suppressing exceptions in C#

I have the following try-catch statement and I do not want to not throw the exception if the message property contains 'My error' in the text. How can I programmatcially accomplish this? Also, would this be considered code-smell? try { } catch(Exception e) { if(e.Messages.Contains("My error")) { //want to display a frie...

Windows workflow - Cannot handle exception in ReceiveActivity

I have a sequential workflow, which is hosted in IIS as a Workflow Service. My workflow starts with a ReceiveActivity, and inside the ReceiveActivity a call is made to a WCF service with a SendActivity. If this call receives an exception, there is a FaultHandlerActivity on my ReceiveActivity which is meant to handle the call, and send a...

Java Exception Handling - Style

Historically I have always written my Exception handling code like this: Cursor cursor = null; try { cursor = db.openCursor(null, null); // do stuff } finally { if (cursor != null) cursor.close(); } But recently, for reasons of readability and laziness, I have started to do this: Cursor cursor = db.openCursor(null, nul...

Fluent NHibernate: Debugging FluentConfigurationException

I'm enjoying using Fluent NHibernate with AutoMappings but every now and then I get this runtime error when trying to create the fluent configuration: 'An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collections, and InnerException for more detail.' Now this can mean all sorts of t...

Using RuntimeExceptions and CheckedExceptions

What are you views on using CheckedExceptions and RuntimeExceptions in an application ? I've been advised to use a combination of both and, as far as I understand, you can have a chain of CheckedException calls being propagated up along with a RuntimeException. ...

bring malloc() back to its initial state

Do you know if there is a way to bring back malloc in its initial state, as if the program was just starting ? reason : I am developing an embedded application with the nintendods devkitpro and I would like to be able to improve debugging support in case of software faults. I can already catch most errors and e.g. return to the console ...

How do I raise an exception in Rails so it behaves like other Rails exceptions?

I would like to raise an exception so that it does the same thing a normal Rails exception does. Specially, show the exception and stack trace in development mode and show "We're sorry, but something went wrong" page in production mode. I tried the following: raise "safety_care group missing!" if group.nil? But it simply writes "ERR...

How to get refences to the instances involved in stack trace of Java exception?

When given an Exception object in Java, is there any way to get (or infer) the instances involved in the stack trace of this exception? I know that StackTraceElement contains information about the classes involved, but what about the actual instances? In case you're wondering, I'd like to use this in a Thread.UncaughtExceptionHandler th...

Possible to call WCF services from Silverlight's global UnhandledException handler?

I'm trying to do something along these lines: private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { try { e.Handled = true; var errorMessage = BuildErrorMessage(e.ExceptionObject); var service = new MyService(Constants.MyBinding, Constants.MyServiceUri); ...

How to catch exception from thread?

I am using a free .net telnet component (De.Mud.Telnet), which has several asynchronous methods you can call, and the component fires events when things happen. My problem is that the component is throwing an exception and I don't know how to catch it. There's no exception event, and the exception doesn't get thrown by my method call. ...

Serializing exceptions over WCF

I have a task running on a remote system connecting back to a server using WCF. It is very possible that the task can throw exceptions, and I'd like those exceptions to be channeled back to the server. Essentially I want to do something like this: Client: server.SendException(new UnauthorizedAccessException("Some Exception")); Server...