SZLMCL Posted July 11, 2011 Share Posted July 11, 2011 Hy! I have a problem with the exception handling in VB.NET & AutoCAD Objectarx 2012. The problem comes forward when I am attached to a database with the macro. PROJECT1: So works (Try Catch catches the error): --------------------------------------------------------- 1. VB.NET -> New Class Library <CommandMethod("TEST")> _Public Shared Sub TEST() [indent]Dim acaddoc As Autodesk.AutoCAD.Interop.AcadDocument = AcadApp.ActiveDocument Dim f As frmTest = New frmTest f.btnTest.PerformClick() f.ShowDialog() [/indent] End Sub 2. Add new Form (frmTest) Public Class frmTestPrivate Sub btnTest_Click(sender As System.Object, e As System.EventArgs) Handles btnTest.Click Try Dim d As Double = "test" MsgBox("OK") Catch ex As Exception MsgBox("ERROR") End Try End Sub End Class 3. When i run te macro with Autocad (Netload, TEST), the error message appears with MsgBox("ERROR"). PROJECT2: Not working (Try Catch no catches the error): ---------------------------------------------------------------- 1. VB.NET -> New Class Library 2. Add new Form (frmTest) 3. Add Data Source with Data Source Wizard. 4. Bind a database table with Datagridview. 5. Build -> NETLOAD in AutoCAD -> TEST The code: Try Dim d As Double = "TEST" Me.TervezokTableAdapter.Fill(Me.ACADDBDataSet.Tervezok) lblServerState.Text = "Online" Catch ex As Exception lblServerState.Text = "Offline" End Try This will appear in AutoCAD: http://kepfeltoltes.hu/110711/hiba2_www.kepfeltoltes.hu_.png When i comment out the 'Dim d As Double = "TEST"' line and i break my internet connection (throw the error manually), then appear this: http://kepfeltoltes.hu/110711/hibaa_www.kepfeltoltes.hu_.png The question of mine why the exception does not work catching in the second case? Greet too the answers! Quote Link to comment Share on other sites More sharing options...
Tyke Posted July 11, 2011 Share Posted July 11, 2011 In your Try you have declared d as a double but assigned a string to it: Try [color=red][i][b] Dim d As Double = "test"[/b][/i][/color] MsgBox("OK") Catch ex As Exception MsgBox("ERROR") End Try Try resolving that problem first. Quote Link to comment Share on other sites More sharing options...
SZLMCL Posted July 11, 2011 Author Share Posted July 11, 2011 In your Try you have declared d as a double but assigned a string to it: Try [i][b][color=red] Dim d As Double = "test"[/color][/b][/i] MsgBox("OK") Catch ex As Exception MsgBox("ERROR") End Try Try resolving that problem first. I did it deliberately, whether should catch the exception or not. Quote Link to comment Share on other sites More sharing options...
Kerry Brown Posted July 11, 2011 Share Posted July 11, 2011 Dim d As Double = "test" Should not compile ... so you won't be able to run the program to test for an error ..... unless VB is not type safe. Quote Link to comment Share on other sites More sharing options...
SZLMCL Posted July 11, 2011 Author Share Posted July 11, 2011 Dim d As Double = "test" Should not compile ... so you won't be able to run the program to test for an error ..... unless VB is not type safe. But this works the PROJECT1 his case. I can compile & run in AutoCAD. The msgbox error message will appear, this is ok. I wanted this. It would be necessary to attain the same result the PROJECT2 his case. The linked error messages appear on the other hand there, and no msgbox (than the PROJECT1 his case). This was the problem. But I realised the solution meanwhile: It is not allowed to import the Autodesk.AutoCAD.Runtime namespace. Catching the exceptions will work then. (PROJECT1 & 2 also). Thx! Quote Link to comment Share on other sites More sharing options...
fixo Posted July 11, 2011 Share Posted July 11, 2011 Try change this line: Catch ex As System.Exception Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.