exception-handling

The right time to handle all exceptions

I've done a few projects so far, and i've noticed that every single one i've written entirely without any exception handling, then at the end I do a lot of tests and handle them all. is it right? i get thousands of exceptions while testing (which I fix right away) that if i've handled it i wouldn't see exactly where it is(when not usi...

Handling Multiple Exceptions within a Method

I am currently working on the maintenance of a piece of code that is a little bit "Exception Happy." Basically, ever method or anything throws Exception. I'm going to work to take care of that, but, in the meantime, I am wondering what is the best way to handle individual exceptions within a smaller block of code, such as a method. Is...

How can catched exception be null (not NullReferenceException)?

Hey I have run into a rather weird little problem. In the following code I can not understand how e can be null; try { //Some Code here } catch (Exception e) { //Here e is null } As far as I know, throw null will be converted to throw new NullReferenceException(). The problem seems to be related to multithreading, as removi...

How to get back to the for loop after exception handling

Hello, I am ready to run this code but before I want to fix the exception handling: for l in bios: OpenThisLink = url + l try: response = urllib2.urlopen(OpenThisLink) except urllib2.HTTPError: pass bio = response.read() item = re.search('(JD)(.*?)(\d+)', bio) .... As suggested here, I added th...

Why does my javascript Catch block not execute?

I feel silly asking this, I must be missing something obvious. My javascript looks as follows... function onNewItemClick(event) { alert('ello!'); try { var xx = 111/0; } catch(exc) { alert('fff'); } } alert('ello!') works like it should, but the alert('fff') in the Catch block never gets called...

"Handle it higher up" definition

In a stack trace, the method call at the top is the most recently called method. When the phrase "handle it higher up" is mentioned, does this mean in the method caller or to call another method in the catch block? Furthermore, in a multi-tier application with an API I wrote, it seems like the best strategy is to always log an exceptio...

C++: do you (really) write exception safe code?

EH seems to be the current standard, and by searching the web, I can not find any novel ideas or methods that try to improve or replace it (well, some variations exist, but nothing novel). Though most people seem to ignore it or just accept it, EH has some huge drawbacks: exceptions are invisible to the code and it creates many, many po...

Raise unhandled exceptions in a thread in the main thread?

There are some similar questions, but none supply the answer I require. If I create threads via threading.Thread, which then throw exceptions which are unhandled, those threads are terminated. I wish to retain the default print out of the exception details with the stack trace, but bring down the whole process as well. I've considered...

Shall I place try...catch block in destructor, if I know my function won't throw exception.

I know destructor shouldn't not throw exception. http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.13 I have the following code : ~a() { cleanup(); } // I do not expect exception being thrown in this function. // If exception really happen, I know that it is something not recoverable. void a::cleaup() { delete p; } In...

Why this performance difference? (Exception catching)

After reading a question here about what things our computer could do in one second I made a little test I had in mind for a while and I'm very surprised by the results. Look: Simple program to catch a null exception, takes almost one second to do 1900 iterations: for(long c = 0; c < 200000000; c++) { try { test = null;...

Does an exception inside a TRY block break its execution?

I'm importing several fields, and that is, about 25 lines of code each importing one field (in my case, there's really no other way). It's in a try-catch block, but there are some times, that this field doesn't exist in the source, but I have to get the rest. from 20. I get 10 the 11th one doesn't exist (exception) I still need from 12 ...

unit tests for screen-scraping?

I'm new to unit testing so I'd like to get the opinion of some who are a little more clued-in. I need to write some screen-scraping code shortly. The target system is a web ui where there'll be copious HTML parsing and similar volatile goodness involved. I'll never be notified of any changes by the target system (e.g. they put a redes...

How to catch connection timeout exceptions from XSD-generated typed DataSets?

This might be a bit complicated, but bear with me. I have a Windows Forms app. It uses strongly typed DataSets via the XSD designer. I am running data access queries via an asynchronous thread, performed like so: // Calling it in code on the main thread: LoadDataList_WorkerCaller dataDelegate = new LoadDataList_WorkerCaller(LoadDataL...

Regarding Catching FaultException<T> ex

Hi I am using Enterprise application block on my application' server side to handle exceptions. I am able to successfully handle exception. I have created a custom service fault class to handle exceptions. Here are my web config enteries... <exceptionPolicies> <add name="WCF Exception Shielding"> <exceptionTypes> <add ...

How to Determine The Module a Particular Exception Class is Defined In

Note: i edited my Q (in the title) so that it better reflects what i actually want to know. In the original title and in the text of my Q, i referred to the source of the thrown exception; what i meant, and what i should have referred to, as pointed out in one of the high-strung but otherwise helpful response below, is the module that t...

How would you like an API to expose error handling?

This title begs for more explanation. Basically, I'm rolling an API that wraps a web service in a nice heirarchical model. This model exposes things in the form: var obj = MyRemoteResource.GetForId(1234, SourceEnum.ThatSource); ApiConsumerMethod(obj.SomeProperty); //SomeProperty is lazily loaded, and often exposes such lazily loaded ...

C# try/catch nightmare

I have a application with similar code (not written by me) try { EnumerateSomeCoolHardwareDevice(); } catch (Exception ex) { } UPDATE - This is .NET C# & EnumerateSomeCoolHardwareDevice() is using SerialPort? I know how bad this code is but it works like this for a reason! My question thou: I can see that it crashes somewhere ...

SQL Server: Rethrow exception with the original exception number

I am using a TRY CATCH block in a stored procedure where I have two INSERT instructions. If something goes wrong, the CATCH block takes care of rolling back all changes made and it works fine, except one thing! The exception caught by my ASP.NET application is a SqlException with number 50000. This is not the original number! (the numb...

When to throw exceptions and when to log them ?

I have a three layer structure 1. Presentation layer 2. Business layer 3. Data Layer The Presentation layer interacts with the business layer via a service facade . Now I am confused on where should I throw my exceptions , where should I log them and where should I catch and swallow them . Currently I am swallowing my exception in ...

What is the best practice for handling exceptions when using command binding in WPF?

I am using the MVVM pattern for a WPF application. In several places I bind commands to input elements in the views as in the following XAML: <Button Command="{Binding TheClickCommand}" >Click</> What is the best practice for handling exceptions thrown when the command is executed in my viewmodel - i.e. what is the best way to inform...