exception-handling

What happens if a throw; statement is executed outside of catch block?

In C++ throw; when executed inside a catch block rethrows the currently caught exception outside the block. In this answer an idea of exception dispatcher is brought up as a solution to reducing code duplication when using complex exception handling often: try { CodeThatMightThrow(); } catch(...) { ExceptionHandler(); } void E...

In Java, is using throws Exception instead of throwing mulitple specific exceptions good practice?

While looking through the Spring MVC framework I noticed that, unless I misunderstand, its developers favor throws Exception instead of throwing multiple exceptions. I realize that at the core of this question is the checked versus unchecked exceptions debate, avoiding that religious war, is it a good practice to use throws generic exce...

How do I keep Vista from killing my program on exceptions?

It used to be that if an exception got raised and propagated far enough up the call stack, Application's main loop would handle it and give you a dialog box. That behavior seems to be broken under Windows Vista. If any exception reaches that level, Vista steps in and says the program "has stopped working," when it used to be perfectly...

How to surround code with try/catch most elegantly

I often have some problems when using try-and-catch: 1) Some variables need to be declared inside the try brackets otherwise they will not be in scope 2) Ultimately even my return statement ends up having to be in the try bracket but then the method doesn't return anything. What is the proper way to get around this sort of problem. A...

Transaction-like style of programming or the wise exception handling

Question by abstract example Suppose you have 2 methods: DoJob1(), DoJob2(). Each of them has transaction-like behavior, that is, either does its job or reports an error. How should I write a method which executes DoJob1() then DoJob2(), but is transaction-like itself, that is, guarantees the roll-back of the action performed by DoJob1...

How can I rethrow an Inner Exception while maintaining the stack trace generated so far?

Duplicate of: http://stackoverflow.com/questions/57383/in-c-how-can-i-rethrow-innerexception-without-losing-stack-trace I have some operations that I invoke asynchronously on a background thread. Sometimes, things go bad. When this happens, I tend to get a TargetInvocationException, which, while appropriate, is quite useless. What I ...

Should web services throw exceptions OR result objects.

I'm not sure I'm completely happy that throwing exceptions in web services is a good idea. I wouldnt mind as much if it wasn't for the stack trace. This is not something I wan't. I have researched around several implementations and there really doesn't seem to be a consensus on this. CampaignMonitor for example does return a Result obj...

Why does resharper say 'Catch clause with single 'throw' statement is redundant'?

I thought throwing an exception is good practice to let it bubble back up to the UI or somewhere where you log the exception and notify the user about it. Why does resharper say it is redundant? try { File.Open("FileNotFound.txt", FileMode.Open); } catch { throw; } ...

When do you write your exception handlers?

At what point during development do you typically implement your exception handlers? Do you write them at the same time as you write the surrounding code, or do you write your code and then come back to "harden" it later? I typically do the latter so that I can see exactly where and how my code fails, but I worry that my code isn't as ...

Unhandled Exception checker plugin for Visual Studio

I would like to be able, at compile time, to ask any given method what possible Exceptions might get thrown by invoking it. The list of Exceptions should include any uncaught Exception that might get thrown in any nested method invokation. Caught Exceptions should not be included in the list as I'm only interested in the Exceptions that ...

mysql unique index used as exception handling method in java

Hi All, I want to know whether is it a good idea to catch exception based on unique index of sql in java. i want to catch an exception like 'duplicate entry for 1-0' if so then handle exception otherwise insert properly in database table? ...

ASP.Net MVC Exception Logging combined with Error Handling

Hi. I am looking for a simple solution to do Exception Logging combined with Error Handling in my ASP.Net MVC 1.0 application. I've read lots of articles, including Questions posted here on StackOverflow, which all provide varying solutions for different situations. I am still unable to come up with a solution that suits my needs. Here...

VBA Error Handling

I am relatively new to VBA (Java/Python are more my thing, along with Haskell). One thing that has shocked and surprised me about VBA is the lack of any "obvious" way to do proper structured error handling. What are some good patterns for error handling in VBA? In particular, what should I do in this situation: ... some code ... ... s...

Jboss 4.2 swallows the stacktrace on causes of EJB Exceptions, how can that be prevented?

In JBoss 4.2.2 (on JDK5), I'm noticing this behavior. Is there a configuration or other way to prevent it? If I have code like this: try { doSomething(); } catch (Exception e) { throw new EJBException(e); } The resulting stack trace (when caught and logged) will be: EJBException .... at(..... at(..... caused by: NullPoint...

MS SQL server casting without exception.

Hello world! Is there any "convert" function in MS SQL server that allows to cast types safely(without throwing exception). I need something like "tryParse" in C# lang but as SQL statement. More detailed, I need the following statement returns zero or any else but throwing exception. select convert(float, 'fjsdhf') thanks in advance...

How can I handle an IOException which I know can never be thrown, in a safe and readable manner?

"The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair." -Douglas Adams I have an class FileItems. FileItems constructor takes a file, and throws an exce...

c# console application - prevent default exception dialog

I have simple application with single AppDomain which is periodicaly launched on a server. Sometimes unhandled exception occurs in the aplication and default abort/retry/ignore dialog pops up. I need to somehow prevent the edialog from showing and just output the exception on StrErr and close the application. So I enclosed all the code i...

General Exception Handling Strategy for .NET

I’m used to having try/catch blocks in every method. The reason for this is so that I can catch every exception at the point of infraction and log it. I understand, from my reading and conversations with others, that this isn’t a popular view. One should only catch what one is prepared to handle. However, if I don’t catch at the point of...

How defensively should I program?

i was working with a small routine that is used to create a database connection: Before public DbConnection GetConnection(String connectionName) { ConnectionStringSettings cs= ConfigurationManager.ConnectionStrings[connectionName]; DbProviderFactory factory = DbProviderFactories.GetFactory(cs.ProviderName); DbConnection conn =...

any way to get some information at least for catch(...)

Is there any way to get at least someinformation inside of here? ... catch(...) { std::cerr<<"Unhandled exception"<<std::endl; } I have this as a last resort around all my code. Would it be better to let it crash, because then I at least could get a crash report? ...