Results 1 to 8 of 8

Thread: Try Catch Block Inside of Sub Main

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474

    Try Catch Block Inside of Sub Main

    When this code runs, all the errors in the forms are handled by the Try Catch of Sub Main. How can I avoid this?
    VB Code:
    1. Module Start
    2.    Sub Main()
    3.         Try
    4.             ' some code here
    5.               Application.Run(New Form1())
    6.         Catch ex as System.Exception
    7.               Messagebox.Show(ex.Message)
    8.         End Try
    9.    End Sub
    10. End Module
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Remove the Application.Run method from the try block.
    Dont gain the world and lose your soul

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    by try catching in other routines being called. If an error happens down the stack and there is no try catch where it happens, the error will be sent back up thew stack until it finds a try catch.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    You mean i should do this?
    VB Code:
    1. Dim frm As New Form1()
    2. frm.ShowDialog()

    I thought there is a difference between this one and Application.Run method regarding the life cycle of the application.
    Last edited by Lunatic3; Apr 3rd, 2003 at 01:22 PM.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Thanks Cander for technical definision of the situation
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Originally posted by Lunatic3
    You mean i should do this?
    VB Code:
    1. Dim frm As New Form1()
    2. frm.Show()
    If this code didn't show the form(for me it didn't work) , then you must show the form modally .

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474

    If this code didn't show the form(for me it didn't work) ..
    Yes you are right, that should be Showdialog. I corrected the post.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width