exception-handling

Exceptions in Web Services

My group is developing a service-based (.NET WCF) application and we're trying to decide how to handle exceptions in our internal services. Should we throw exceptions? Return exceptions serialized as XML? Just return an error code? Keep in mind that the user will never see these exceptions, it's only for other parts of the applicatio...

catching all types of exceptions in C++ in one catch block

in c++, Iam trying to catch all types of exceptions in one catch (like catch(Exception) in C#). how is it done ? and more, how can one catch devide-by-zero exceptions ? ...

Exception Handling in .net web apps

I admit it: I don't bother with too much exception handling. I know I should do more but I can never wrap my head around where to start and where to stop. I'm not being lazy. Far from it. It's that I'm overwrought with exception handling ambivalence. It just seems that there is a seemingly infinite number of places in even the smalle...

UnhandledException handler in a .Net Windows Service

Is it possible to use an UnhandledException Handler in a Windows Service? Normally I would use a custom built Exception Handling Component that does logging, phone home, etc. This component adds a handler to System.AppDomain.CurrentDomain.UnhandledException but as far as I can tell this doesn’t achieve anything win a Windows Service so ...

Debug.Assert vs. Specific Thrown Exceptions

Hi, I've just started skimming 'Debugging MS .Net 2.0 Applications' by John Robbins, and have become confused by his evangelism for Debug.Assert(...). He points out that well-implemented Asserts store the state, somewhat, of an error condition, e.g.: Debug.Assert(i > 3, "i > 3", "This means I got a bad parameter"); Now, personally, ...

Exception handling in Delphi

Is there a good way to find out which exceptions a procedure/function can raise in Delphi (including it's called procedures/functions)? In Java you always have to declare which exceptions that can be thrown, but this is not the case in Delphi, which could lead to unhandled exceptions. Are there any code analysis tools that detects un...

How to catch ALL exceptions/crashes in a .NET app

I have a .NET console app app that is crashing and displaying a message to the user. All of my code is in a try{} catch(Exception e){} block, but still errors are occasionally displayed. In a Win32 app, you can capture all possible exceptions/crashes by installing various exception handlers: _set_se_translator SetUnhandledExceptionFil...

How to properly handle exceptions when performing file io

Often I find myself interacting with files in some way but after writing the code I'm always uncertain how rubust it actually is. The problem is that I'm not entirely sure how file related operations can fail and, therefore, the best way to handle expections. The simple solution would seem to be just to catch any IOExceptions thrown by ...

How to prevent the ObjectDisposedException in C# when drawing and application exits

I'm a CompSci student, and fairly new at C#, and I was doing a "Josephus Problem" program for a class, and I created an Exit button that calls Application.Exit() to exit at anytime, but if C# is still working on painting and the button is pressed it throws an ObjectDisposedExeception for the Graphics object. Is there any way to prevent t...

Should I catch exceptions only to log them?

Should I catch exceptions for logging purposes? public foo(..) { try { ... } catch (Exception ex) { Logger.Error(ex); throw; } } If I have this in place in each of my layers (DataAccess, Business and WebService) it means the exception is logged several times. Does it make sense to do so if my layers are in...

Does an application-wide exception handler make sense?

Long story short, I have a substantial Python application that, among other things, does outcalls to "losetup", "mount", etc. on Linux. Essentially consuming system resources that must be released when complete. If my application crashes, I want to ensure these system resources are properly released. Does it make sense to do something...

How can I catch AWT thread exceptions in Java?

We'd like a trace in our application logs of these exceptions - by default Java just outputs them to the console. ...

Exceptions: Is this a good practice?

This is written in PHP but it's really language agnostic. try { try { $issue = new DM_Issue($core->db->escape_string($_GET['issue'])); } catch(DM_Exception $e) { throw new Error_Page($tpl, ERR_NOT_FOUND, $e->getMessage()); } } catch(Error_Page $e) { die($e); } Is nested try, catch blocks a g...

Performance of try-catch in php

What kind of performance implications are there to consider when using try-catch statements in php 5? I've read some old and seemingly conflicting information on this subject on the web before. A lot of the framework I currently have to work with was created on php 4 and lacks many of the niceties of php 5. So, I don't have much experi...

What are the principles guiding your exception handling policy?

There is a lot of relativity involved in working with exceptions. Beyond low level APIs where exceptions cover errors raised from hardware and the OS there is a shady area where the programmer decides what constitutes an exception and what is a normal condition. How do you decide when to use exceptions? Do you have a consistent policy r...

Use of the Exception class in c#

Errors that occur deep down in a data access layer or even higher up, (say within ADO.net operations for example) rarely make much sense to an end user. Simply bubbling these errors up to a UI and displaying them will usually achieve nothing except frustration for an end user. I have recently employed a basic technique for reporting err...

Conditions when finally does not execute in a .net try..finally block

Basically I've heard that certain conditions will cause .net to blow past the finally block. Does anyone know what those conditions are? ...

Why Re-throw Exceptions?

I've seen the following code many times: try { ... // some code } catch (Exception ex) { ... // Do something throw new CustomException(ex); // or // throw; // or // throw ex; } Can you please explain the purpose of re-throwing an exception? Is it following a pattern/best practice in exception handling? (I...

Is there a way to determine if an exception is occurring?

In a destructor, is there a way to determine if an exception is currently being processed? ...

Pattern for trying different methods when exception is thrown

Here's a question to expose my lack of experience: I have a method DoSomething() which throws an exception if it doesn't manage to do it cleanly. If it fails, I try the less accurate method DoSomethingApproximately() several times in the hope that it will find a sufficiently good solution; if this also fails I finally call DoSomethingIna...