Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JK JK is offline
external usenet poster
 
Posts: 78
Default Error Trapping

For many of my procedures I trap errors with On Error GoTo Handler. Would it
be best to add Resume Next to the Handler?

Sub ()
On Error GoTo Handler
[code]
Exit Sub

Handler:
[whatever]
Resume Next
End Sub

Or is there a better approach? Thank you in advance.

Jim Kobzeff


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Error Trapping

It depends what you want to happen when an error occurs. If your
error handling code can fix the error, use Resume or Resume Next
to resume execution in the main section of the code. If your
error handling code can't fix the error, you probably don't want
to resume, instead exit the sub.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"JK" wrote in message
news:HhpNf.2710$DT.491@trnddc06...
For many of my procedures I trap errors with On Error GoTo
Handler. Would it be best to add Resume Next to the Handler?

Sub ()
On Error GoTo Handler
[code]
Exit Sub

Handler:
[whatever]
Resume Next
End Sub

Or is there a better approach? Thank you in advance.

Jim Kobzeff



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Error Trapping

That depends entirely on the nature of the error. If the error is critical
and there is no point in going onn after the error then resuming next would
not cut it. For example if the code needs to read some data from another
file, if that file can not be found, it may not make sense to continue on
with the code. On the other hand, if it can not find the file but you can
reasonably expect the end user to be able to find the file, then your error
handler may just show a find file dialog. Once the file has been located then
continue. If the user can not find the file then you still would just end the
process.

There are as many correct ways to handle an error as there are possible
errors.
--
HTH...

Jim Thomlinson


"JK" wrote:

For many of my procedures I trap errors with On Error GoTo Handler. Would it
be best to add Resume Next to the Handler?

Sub ()
On Error GoTo Handler
[code]
Exit Sub

Handler:
[whatever]
Resume Next
End Sub

Or is there a better approach? Thank you in advance.

Jim Kobzeff



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Trapping from WSH Tom Chau Excel Discussion (Misc queries) 1 August 25th 06 04:21 AM
Error Trapping Rafi Excel Programming 3 February 14th 06 11:42 PM
Error trapping Steve Excel Programming 2 October 17th 05 10:52 PM
error trapping [email protected] Excel Programming 2 April 5th 05 12:52 AM
error trapping libby Excel Programming 5 November 25th 03 10:57 PM


All times are GMT +1. The time now is 02:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"