exception-handling

Exception handling using an HttpModule

We're reviewing one of the company's system's exception handling and found a couple of interesting things. Most of the code blocks (if not all of them) are inside a try/catch block, and inside the catch block a new BaseApplicationException is being thrown - which seems to be coming from the Enterprise Libraries. I'm in a bit of a troub...

Catching exceptions as expected program execution flow control?

I always felt that expecting exceptions to be thrown on a regular basis and using them as flow logic was a bad thing. Exceptions feel like they should be, well, the "exception". If you're expecting and planning for an exception, that would seem to indicate that your code should be refactored, at least in .NET... However. A recent scen...

Avoid throwing a new exception

I have an if condition which checks for value and the it throws new NumberFormatException Is there any other way to code this if (foo) { throw new NumberFormatException } // .. catch (NumberFormatException exc) { // some msg... } ...

Is there a good way around the problems of structured exception handling (__try __except) with a multi-threaded server?

This article gives a good overview on why structured exception handling is bad. Is there a way to get the robustness of stopping your server from crashing, while getting past the problems mentioned in the article? I have a server software that runs about 400 connected users concurrently. But if there is a crash all 400 users are effec...

What is the proper way to re-throw an exception in C#?

Duplicate: http://stackoverflow.com/questions/22623/net-throwing-exceptions-best-practices I have a question for you that stems from my partner doing things a different way than I do. Is it better to do this : try { ... } catch (Exception ex) { ... throw; } or this: try { ... } catch (Exception ex) { ... throw ex; } Do they...

C# equivalent to VB.NET Catch ... When

In VB.NET I often Catch ... When ... Try ' Some code' Catch e As ArgumentNullException When e.ParamName.ToUpper() = "SAMPLES" ' Handle the error' End Try Is there a C# equivalent to Catch ... When? I don't want to resort to using an if statement inside a catch if possible. ...

C# Windows Forms - Best Practice Exception Handling?

I'm currently in the process of writing my first Windows Forms application. I've read a few C# books now so I've got a relatively good understanding of what language features C# has to deal with exceptions. They're all quite theoretical however so what I haven't got yet is a feel for how to translate the basic concepts into a good except...

Is it possible to detect if an exception occurred before I entered a finally block?

In Java, is there an elegant way to detect if an exception occured prior to running the finally block? When dealing with "close()" statements, it's common to need exception handling within the finally block. Ideally, we'd want to maintain both exceptions and propogate them up (as both of them may contain useful information). The only way...

How do I catch ClassCastException?

I'm trying to catch a ClassCastException when deserializing an object from xml. So, try { restoredItem = (T) decoder.readObject(); } catch (ClassCastException e){ //don't need to crash at this point, //just let the user know that a wrong file has been passed. } And yet this won't as the exception do...

Enterprise Library Review?

Hi, Is enterprise library for exception handling and logging efficient in terms of its memory usage for the functionality provided? What are the pros and cons? Thanks ...

catching exceptions from another thread

I have a method running in a seperate thread. The thread is created and started from a form in a windows application. If an exception is thrown from inside the thread, what is the best way to pass it back to the main application. Right now, I'm passing a reference to the main form into the thread, then invoking the method from the thr...

How to configure spring HandlerExceptionResolver to handle NullPointerException thrown in jsp ?

From a jsp is thrown a NullPointerException for example using <% null.toString(); %> This exception is not handled by the HandlerExceptionResolver, but thrown to the web container(tomcat) and converted into a code 500 error. How can I configure spring to get that error in my HandlerExceptionResolver ? Details: Spring can be configu...

In C++ what are the benefits of using exceptions and try / catch instead of just returning an error code?

I've programmed C and C++ for a long time and so far I've never used exceptions and try / catch. What are the benefits of using that instead of just having functions return error codes? ...

Debugging with exceptions: How to work around 'Break when thrown'

I'm getting tired of clearing the Debugging->Exceptions option Break when thrown to get past an exception I handle properly, then setting the Break when thrown option to find the source of a subsequent exception not handled properly. I would like a way to exclude certain try blocks from Break when thrown, with something like preprocesso...

Behaviour of exceptions within delegates in C# 2 hosted by MS Excel and COM

Morning all, Bit of a language theory question here... I've found some references online suggesting that exception handling and delegates in C# have some different behaviour in some cases but I cannot find any concrete documentation on the matter. We recently had some big problems with exceptions inside delegates for a Microsoft Excel ...

Why does my JNI code not successfully find a jthrowable's getMessage method?

I'm trying to access the message in a jthrowable while handing an exception generated when I fail to find a class. However, I am unable to access the message ID of getMessage() on the jthrowable object, and I don't know why. I've tried changing the signature of getMessage to "()Ljava/lang/String" (without the semicolon at the end, but ...

.NET - What's the best way to implement a "catch all exceptions handler"

I'm wondering what the best way is to have a "if all else fails catch it". I mean, you're handling as much exceptions as possible in your application, but still there are bound to be bugs, so I need to have something that catches all unhandled exceptions so I can collect information and store them in a database or submit them to a web s...

ExceptProc not being called in Windows

I am currently trying to create an Exception handler built into my windows service that, on an unhandled exception, sends a message to another program. I have built the method and gotten the communication working, but it seems that every time my program throws the error, (I have a raise call in the code to force it.) windows catches it...

Best way to throw exceptions in JNI code?

I'd like a consistent and simple way to throw exceptions in JNI code; something that handles chained exceptions (implicitly from the env->ExceptionOccurred method, or explicitly by parameters, either way is good) and saves me looking up constructors every time I want to do this. All of the above is preferably in C, although I could tran...

Checked exception catching in C#

Java requires that you catch all possible exceptions or declare them as thrown in the method signature. This isn't the case with C# but I still feel that it is a good practice to catch all exceptions. Does anybody know of a tool which can process a C# project and point out places where an exception is thrown but not caught? ...