Jump to content

Try..Catch not working VB.NET & ObjectARX


SZLMCL

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. :o

Link to comment
Share on other sites

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. :o

 

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!

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...