BuZz
BuZz

Reputation: 17495

debug and break on null pointer exceptions only

enter image description here

I have to debug a big messy C# tool which I didn't write, that parses an Excel file in a specific format (containing exotic data in quantity).

The run of the tool lasts for about 15 minutes and produces an error report (thousands of entries in general). Trouble is that the coder has used exceptions everywhere for his "error reporting", and I need to find a few null pointer exceptions that occur about 2% of the time. I'm not even talking about all the catching, grouping, rethrowing which is bad practice in my understanding, both in terms of consistency and rapidity of execution.

Is there a way to only break on Null Pointer Exceptions in Visual Studio (2008) or at least a trick to filter most exceptions ? Breaking on all exceptions is not an option here.

Upvotes: 2

Views: 3514

Answers (4)

Ian
Ian

Reputation: 34529

Within Visual Studio press CTRL+ALT+E or goto Debug->Exceptions. In the dialog that appears check the 'Thrown' box for NullReferenceException. You may wish to use the Find button to locate it.

enter image description here

Upvotes: 4

Rik
Rik

Reputation: 29243

In Visual Studio, under Debug -> Exceptions, you can specify for which exception it should break.

You can find the NullReferenceException under:

CommonLanguage Runtime Exceptions

  • System
    • System.NullReferenceException

Upvotes: 10

Pondidum
Pondidum

Reputation: 11637

Put a tick in the "Thrown" column here:

Debug -> Exceptions -> Common Language Runtime Exceptions -> System -> System.NullReferenceException

Upvotes: 2

mihail
mihail

Reputation: 2173

the fastest thing I think of is to find all catch (strings and replace them with

catch (NullReferenceException npe)
        {
        //something your logging here
        }
        catch (

then add breakpoints if you need only in these catch sections

Upvotes: 4

Related Questions