Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I've been developing Add-ins for a while with Visual Studio 2008 and ArcGIS 10. But in my new Add-in development process, I receive no error from Visual studio and ArcGIS crashes with error "Arcgis encountered serious application error and need to be closed".

I tried setting breakpoints and the program stops correctly at the breakpoint. But when I use F8 to proceed, I can identify the line which has the error but no error screen from Visual studio appears, as normal.

Can you help me? This way I can't debug and specify exact problem in my code

share|improve this question
1  
can you post part of code? This is not uncommon, and could be any number of errors in the ArcObjects code. –  JeremyFon May 17 '13 at 12:04
add comment

1 Answer 1

The first thing you should do is put Try..Catch blocks in your code. This will make it much easier to figure out why the code is crashing. Here is an example

Private Sub FindSmallestPolygon()

    'This requires the feature class to be in a geodatabase 
    'or has the field "Shape_Area" already calculated with the area

    Dim pLayer As ESRI.ArcGIS.Carto.ILayer = My.ArcMap.Document.FocusMap.Layer(0)
    Dim pFLayer As New ESRI.ArcGIS.Carto.FeatureLayer
    Dim pFClass As ESRI.ArcGIS.Geodatabase.IFeatureClass
    Dim pFCursor As ESRI.ArcGIS.Geodatabase.IFeatureCursor
    Dim pQFilter As New ESRI.ArcGIS.Geodatabase.QueryFilter
    Dim pFeature As ESRI.ArcGIS.Geodatabase.IFeature
    Try
        pFLayer = pLayer
        pFClass = pFLayer.FeatureClass
        pQFilter.WhereClause = Chr(34) & "Shape_Area" & Chr(34) & " = (Select Min(" & Chr(34) & "Shape_Area" & Chr(34) & ") from " & pFLayer.Name & ")"
        pFCursor = pFClass.Search(pQFilter, False)

        pFeature = pFCursor.NextFeature
        MsgBox(pFeature.OID)

    Catch ex As Exception
        System.Windows.Forms.MessageBox.Show(ex.ToString)
    End Try
End Sub

The message box should give you an indication of what's gone wrong in the code without crashing ArcMap and often contains the line number where the error occurs.

share|improve this answer
    
I'm aware of Try/Catch block. Maybe i haven't expressed my problem properly. I'm in development process, so i need to know where might be prolematic codes. Providing good information for user while preventing from ArcMap crash is something else. Execution should be stopped in Visual studio with a yellow line indicating the place of problem and a message containing error no, but i don't see this. I just see a big window in ArcMap which says it has crashed. was it clear? @JeremyFon –  alavi May 17 '13 at 13:27
    
When I leave out Try/Catch blocks, I will more often get a total crash of ArcGIS with no explanation. I've done other things in the Catch block, such as bringing up a dialog box that allows the user to send me the error message via email –  kenbuja May 17 '13 at 13:39
    
User? Now, there is no user except me, i.e. developer and while i'm running (=testing=debugging) my Addin via Visual studio, It must tell which line has error and which error. Isn't it? –  alavi May 17 '13 at 14:42
    
It might be helpful to post the code that is giving you a problem –  kenbuja May 17 '13 at 15:00
    
It doesn't matter which code. Suppose this in VB.NET: MsgBox ( "a" + 1). This line causes an error and Visual studio must show me this line in yellow but i don't receive any error from VS. I just see ArcGIS (which load by VS) crashes. –  alavi May 17 '13 at 15:06
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.