Try...Catch Ex As Exception
Use this board to post your code snippets - tips and tricks
2 posts
Page 1 of 1
Hi all !
This little snip will help you with unwanted errors, and it also give you the ability of what you want to do when an error hit.
So the little code is
The Try is like saying, Try to run this code.
The Catch Ex As Exception - If there's no errors then VB will skip this, but if there's any error it will go here
and below Catch Ex As Exception you have MsgBox(ex.Message)
So if you have an error when the code try to execute, it will go to Msgbox(ex.Message)
Basically Ex.Message will tell you what your Error is
End Try will stop what you're trying to run
EDIT: Oh I also forgot something, Msgbox(ex.Message) will show you a Msgbox with the error, if you want to close your program after that error then just add
This little snip will help you with unwanted errors, and it also give you the ability of what you want to do when an error hit.
So the little code is
Code: Select all
okay so let me explain a bit.Try
'your code here
Catch Ex As Exception
MsgBox(ex.Message)
End Try
The Try is like saying, Try to run this code.
The Catch Ex As Exception - If there's no errors then VB will skip this, but if there's any error it will go here
and below Catch Ex As Exception you have MsgBox(ex.Message)
So if you have an error when the code try to execute, it will go to Msgbox(ex.Message)
Basically Ex.Message will tell you what your Error is
End Try will stop what you're trying to run
EDIT: Oh I also forgot something, Msgbox(ex.Message) will show you a Msgbox with the error, if you want to close your program after that error then just add
Code: Select all
right after Msgbox(ex.Message)End
Last edited by NoWayIn on Sun Apr 11, 2010 6:24 am, edited 1 time in total.
2 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023