Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net捕获一个“捕获”;断言失败;?_Vb.net_Try Catch_Assertion - Fatal编程技术网

Vb.net捕获一个“捕获”;断言失败;?

Vb.net捕获一个“捕获”;断言失败;?,vb.net,try-catch,assertion,Vb.net,Try Catch,Assertion,所以我正在使用的程序有一个“进程文件”按钮,它打开一个选择文件对话框,你可以选择一个文本文件。然后,软件调用一个函数,该函数将其导入C中的DLL库并返回结果 这一切都可以正常工作,除非您试图处理的文件被移动或删除。VB抛出一个大的“断言失败”消息框,说str=!空(我猜是真的)。我有一个“try,Catch”语句中的函数 为什么它不抓住它 我知道我可以在处理文件之前验证文件是否存在,但是删除文件是一个测试,以查看try,catch是否有效,这是因为断言框很大 =================

所以我正在使用的程序有一个“进程文件”按钮,它打开一个选择文件对话框,你可以选择一个文本文件。然后,软件调用一个函数,该函数将其导入C中的DLL库并返回结果

这一切都可以正常工作,除非您试图处理的文件被移动或删除。VB抛出一个大的“断言失败”消息框,说str=!空(我猜是真的)。我有一个“try,Catch”语句中的函数

为什么它不抓住它

我知道我可以在处理文件之前验证文件是否存在,但是删除文件是一个测试,以查看try,catch是否有效,这是因为断言框很大

==========================================================================

        Try
            ProcessSongResult = ProcessSongInC(old_key(0),
                              new_key(0),
                              output_mode(0),
                              lyrics_mode(0),
                              display_format(0),
                              blank_line_mode(0),
                              song_file_path(0),
                              screen_width,
                              screen_height,
                              paper_width,
                              paper_height,
                              error_msg(0),
                              transposed_song(0),
                              num_columns,
                              column_1_end,
                              column_2_end,
                              font_size,
                              total_lines,
                              tsi(0),
                              ischord(0))

        Catch ex As Exception
            MsgBox("Tranposing error encountered. Choose different settings and try again.", MsgBoxStyle.Critical, "Transposing Error Encountered!")
            Exit Sub

        End Try

Public Declare Function ProcessSongInC Lib "LMSdll.dll" (
    ByRef old_key As Byte,
    ByRef new_key As Byte,
    ByRef output_mode As Byte,
    ByRef lyrics_mode As Byte,
    ByRef display_format As Byte,
    ByRef blank_lines_mode As Byte,
    ByRef song_file_path As Byte,
    ByVal screen_width As Integer,
    ByVal screen_height As Integer,
    ByVal paper_width As Integer,
    ByVal paper_height As Integer,
    ByRef err_msg As Byte,
    ByRef TransposedSong As Byte,
    ByRef num_columns As Integer,
    ByRef column_1_end As Integer,
    ByRef column_2_end As Integer,
    ByRef font_size As Integer,
    ByRef total_lines As Integer,
    ByRef tsi As Integer,
    ByRef ischord As Byte
    ) As Integer

您是否阅读了
Debug.Assert
方法的文档?它所做的就是重点。它应该在调试期间提供关于特定条件的特定信息。关键是,在执行受断言测试条件影响的操作之前,先放置一个断言。调试时,您从断言中获得消息,而在发布版本中,您只会从后面的代码中抛出异常。你看到的是你应该看到的。如果要避免断言,请运行发布版本。

请向我们显示“try,Catch”语句好吗?VB会抛出一个大的“断言失败”消息框。它不是,它来自C代码,assert()函数显示它。这不是一个例外,因此Try/Catch完全不起任何作用。除非知道所有参数都有正确的值,否则不要调用该函数。Fwiw,处理该LMSdll.dll文件的最佳方法是将其从磁盘中删除。