none
VB.net disable all error message box pop up RRS feed

  • Question

  • hi.

    its it possible to block / disable auto generate error message box .

    using below code (i found in the one of the forum) i manage to stop error message "Divide by zero"  but not "overflow "

     Private Declare Sub keybd_event Lib "user32" _
                           (ByVal bVk As Byte, _
                            ByVal bScan As Byte, _
                            ByVal dwFlags As Byte, _
                            ByVal dwExtraInfo As Byte)
    
        Private Const VK_RETURN As Byte = &HD
        Private Const KEYEVENTF_KEYDOWN As Byte = &H0
        Private Const KEYEVENTF_KEYUP As Byte = &H2
        '   Private Const Text As String = "test"
    
        Private Sub closeMsgbox(ByVal delay As Object)
            Threading.Thread.Sleep(CInt(delay) * 0)
            AppActivate(Me.Text)
            keybd_event(VK_RETURN, 0, KEYEVENTF_KEYDOWN, 0)
            keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0)
        End Sub
       
    
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    
            Dim t As New Threading.Thread(AddressOf closeMsgbox)
            Dim t1 As New Threading.Thread(AddressOf msgboxautoclose)
    
            t.Start(0) '10 second delay
    
    end sub
           
    

    any ide ?

    Thursday, November 15, 2018 9:38 AM

All replies

  • Hello,

    You can use Try catch in your case

    for reference

    https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/try-catch-finally-statement

           Try
                'Your Code
            Catch ex As Exception
                Dim errormsg As String = String.Empty
                errormsg = ex.ToString()
            End Try
    

    Thursday, November 15, 2018 9:44 AM
  • oh ya forgot to mention 

    the error came from Function within the DLL  file (i dont have the source code) , hence 

    Try 

    Catch ex Exception

    not working 

    Thursday, November 15, 2018 9:52 AM
  • Ok but have you tried by moving the instantiation of the class [In dll] within the try block
    Thursday, November 15, 2018 9:58 AM
  • oh ya forgot to mention 

    the error came from Function within the DLL  file (i dont have the source code) , hence 

    Try 

    Catch ex Exception

    not working 


    The problem is you are just copying random code you find without understanding what it does.

    You need to prevent the call that causes divide by zero. That will solve the problem.

    Thursday, November 15, 2018 9:59 AM
  • Hello,

    You can use Try catch in your case

    for reference

    https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/try-catch-finally-statement

           Try
                'Your Code
            Catch ex As Exception
                Dim errormsg As String = String.Empty
                errormsg = ex.ToString()
            End Try

    Tech,

    Try catch does not solve all the worlds problems. You use it too much in your examples IMHO.

    The only reason to use it is for errors you cant determine by testing like file read etc.

    Most errors can be removed from code with a bit of effort especially divide by zero and overflow.

    Try catch is last resort, just in case.

    Thursday, November 15, 2018 10:03 AM
  • Yes i agree with you I use try catch just to protect my application from crashing if in case any loop holes kept by mistake from my end. I pass my exceptions in log files on deployment.
    Thursday, November 15, 2018 10:07 AM
  • Yes i agree with you I use try catch just to protect my application from crashing if in case any loop holes kept by mistake from my end. I pass my exceptions in log files on deployment.

    Yes I do too. In fact I put it around every event that can do funny "user errors" etc so app wont crash to the system but gets handled nicely by my app.

    Still one should debug their app not depend on try catch.

    In this case if X <> 0 then call sub else deal with it some other way.

    :)


    Thursday, November 15, 2018 10:13 AM
  • In this case if X <> 0 then call sub else deal with it some other way.

    Yes this is the right way

    Thursday, November 15, 2018 10:19 AM
  • Hello,

    Can you show your code which calls the external DLL along with explaining what the code is doing. The exception being thrown may be your code passing data that exceeds what a function expect or is a bug in the external code.

    Also if possible contacting the author of the DLL might be worth trying if the author is known.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, November 15, 2018 10:30 AM
    Moderator
  • You can disable all error messages if you let the error be caught at one spot in the code, all error messages are handled at one spot and central spot. No matter if a DLL throws the exception message, the central spot gets the error,  and you do whatever you want with the error message.

     
    Thursday, November 15, 2018 1:00 PM
  • Hi DA924x

    sound promising.  any ide how to ??

    Friday, November 16, 2018 2:18 AM
  • Hi,

    try the AppDomain.CurrentDomain.UnhandledException

    Imports System.Threading
    
    Public Class Form1
        Shared m_count As Integer = 0
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf CurrentDomain_UnhandledException
    
            While True
                Func1()
                Thread.Sleep(10)
            End While
        End Sub
        Private Shared Sub CurrentDomain_UnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
            MsgBox("there are unhandled exceptions, the program is about to exit")
            Thread.Sleep(5000)
            Environment.Exit(-1)
        End Sub
    
        Private Shared Sub Func1()
            m_count += 1
    
            If m_count > 100 Then
                Throw New Exception()
            End If
        End Sub
    End Class
    

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 16, 2018 3:30 AM