exception-handling

Catching Exception, do's and dont's

Is it always a bad programming technique to leave a catch block empty when using a try-catch block? In cases where I am expecting an exception, for example, I am reading 10 values from a file...and converting each value into a String. There is a possibility that one of the 10 values can be a null, but I don't want to stop my execution a...

Example of "using exceptions to control flow"

Hi, What would a piece of code which "uses exceptions to control flow" look like? I've tried to find a direct C# example, but cannot. Why is it bad? Thanks ...

Catching Rackspace Cloudfiles Exceptions

Hi all, I'm having trouble catching exceptions when using the rackspace cloudfiles api com.mosso.cloudfiles. I have the dll referenced and can perform actions against my cloudfiles account, but when I want to try to catch an exception such as ContainerAlreadyExistsException, I get the error The type or namespace cannot be found. I've al...

catch all exceptions in the application with just one try-catch

Hello, Is there any way to catch all the excepions within an application at Main() with a single try-catch irrespective of threads and appdomains within the application?? In other words I just want to use one try-catch to log all the errors in my application instead of using multiple try catches in various places. Would appreciate any...

Differentiate between Oracle error and warning messages

I am wondering if there is a way to differentiate between warning messages and error messages in Oracle? Does a Warning message count as an exception? Are warning just errors? Is there a clear difference? And if so, is there a way to catch warning messages explicitly, or information messages? Thanks for any advice. ...

how to handle all sql exceptions throughout the page.

"I DONOT WANT TO use the default error page tachnique, because i donot want the webpage to redirect!" yes there is the try and catch yes there are way to add exception handling mathods overwrite for controls but what i need is, it may just be a simple sql command,it may be a control such as formview, it may be a control such as datag...

Unit test behaviour after exception is thrown?

Hi all, I am just starting out with unit testing and have a scenario I'm not sure how to appraoch and my solution doesn't feel right. I have a bit of code that does something, if it fails i.e. throws an exception the exception is caught and logged as below. public T CreateTypedObjectInstance<T>() { T o = default(T); try ...

Is it better to design an Application Exception hierarchy around RuntimeException or Error?

Possible Duplicate: Unchecked exceptions in Java: Inherit from Error or RuntimeException? Looking at how our applications do error handling, we have been steadily moving from a checked ExceptionHierarchy (e.g. Exception -> ApplicationException -> SomethingSpecificBadHappenedException) since in many cases we have many long call...

Handling Exceptions in a .NET 4.0 Task Parallel Library Task

I'm working on a Web Hook in .NET 4.0 that will run a lambda asynchronously and then post the result to a given URI when it is finished. I've got that to work, but now I want the Task to handle any exceptions that are thrown, and am finding it difficult to stop them from reaching the parent. Here's part of my code: private readonly Fu...

Ignore ThreadAbortException when logging exceptions

What's the correct way of ignoring ThreadAbortException when logging exceptions? Is it safe to just catch it in an empty catch block to make it disappear? ...

Automatic locking/unlocking using scope in C++ (from C# background)

I've been using C# for the last few years and I am currently bug fixing in C++. In C# I could use lock on an object to make my code thread safe with: lock(lockObject) { // Do some work } This would unlock the lockOject if there was an exception within the // Do some work Is there something similar in C++? At the moment I can thin...

Does throwing exception in JS property assignment in Rhino makes sense?

I came across a design that overrides [Scriptable.put][1] in a subclass of ScriptableObject to do some conversion. If the conversion fails the code is throwing an exception. Which means that property assignments like following code can cause a runtime exception to be thrown aScriptable.dateOfArrival = aVar; By default rhino would...

Exception Value field is blank when throwing custom exceptions in django

I have custom exceptions in my django project that look like this: class CustomFooError(Exception): def __init__(self, msg="Something went wrong with Foo."): self.msg = msg def __str__(self): return repr(self.msg) At various points in my code I will raise exceptions like this: raise CustomFooError("Things a...

C# Pass Encrypted Data from a file into a memory stream. Throwing exception.

Sort of a continuation from an earlier question, done a bunch of googling, but I don't think I'm on the right path here. Essentially what I'm doing is opening a file with a segment of code like so: byte[] cipherText = File.ReadAllBytes(encryptedFile); Then passing that byte array to a static bool method which calls the actual decrypti...

Coming back to life after Segmentation Violation

Is it possible to restore the normal execution flow of a C program, after the Segmentation Fault error? struct A { int x; }; A* a = 0; a->x = 123; // this is where segmentation violation occurs // after handling the error I want to get back here: printf("normal execution"); // the rest of my source code.... I want a mechanism s...

JAX-RS using exception mappers

Hello, I have read that I can create an implementation of javax.ws.rs.ext.ExceptionMapper that will map a thrown application exception to a Response object. I've created a simple example which throws an exception if the phone length is greater than 20 characters when persisting the object. I am expecting the exception to be mapped to...

Throw exception in try block

try { if (isFileDownloaded) //do stuff else throw new CustomException() } catch (Exception e) { // something went wrong save error to log } finally { //release resources } My question is would the catch catches the ApplicationException thrown in the try bl...

Rethrowing an Exception causing containing Catch to reexecute

Using PHP 5.3.2 I'm handling an Exception in a catch block. After logging the error, I want to pass it on for the Framework to handle. When I try to rethrow the exception, throw $e, the current catch block is reexecuted causing a duplicate entry in my log and then the exception is passed on up. ...

How do make your Ruby scripts robust with proper exception handling

I'm not asking about how to use the begin..rescue statement in Ruby. Rather, I'm asking how do you figure out what's worth worrying about. I know some hardcore people probably go through the documentation/code to find every single possible error, and have code that handles all cases gracefully. But that might be going too far if you're n...

How do I log a general exception to the Event Log?

I have a windows service, in which I want a top level try-catch that catches any otherwise unhandled (or bubbled) exception, logs it to the Event Log and then swallows it so the service keeps running. However, I can't find any overload to System.Diagnostics.EventLog.WriteEntry that takes an exception as a parameter - is there no way to j...