How will u handle error in vb application ? explain

Questions by pghare

Showing Answers 1 - 3 of 3 Answers

Sourav Banerjee

  • May 30th, 2006
 

If You  want To Trap The Error In Visual Basic Code then

Write The Code In Every Procedure & Function

Public Sub xxxxx()

On Error Goto Err_xxxxx

Err_xxxxx:

   if err.Number<>0 then

           msgbox err.description

   end if

End Sub

  Was this answer useful?  Yes

it can be done in one more way like

on error goto err_handler

err_handler:

MsgBox err.number & vbcrlf & err.description & vbcrlf & err.source

err.clear

this will show u the error description

  Was this answer useful?  Yes

Jon

  • Nov 24th, 2006
 

Simple error handling at the top level is fairly easy - Something of the formOn error goto ErrhandlerErrHandler: if err = 237 then resume next ' trivial, not serious else msgbox err.description end if---However, if an error happens in a lower class or activex control, different error handling should be used.In asynchronous classes, the best solution is to raise an error event to be trapped by the higher level program, however, unless the higher level program is properly written, this error is liable to get lost. (You can help fix this by introducing interfaces)In synchronous classes, passing an error string back (by pointer possibly) and checking it at the top level is advisable, for exampleRS = MySQLClass(ErrorString, SQL)if len(ErrorString) > 0 then ' handle the error, msgbox it, etc.end if

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions