Feelings on error handling

L

Legacy 96851

Guest
Hopefully this is the right forum for this, I'd say it's more a discussion than a problem.

I was curious how necessary/encouraged error handling (i.e. the use of "On Error" statements) is in VBA. The fact is, after the past 3 weeks of nothing but Excel, I'm at the point where I know the syntax and can make my macros work with minimal assistance, but I'd like to clean them up a little bit. I'm currently in the process of rewriting a few from scratch, and started to think about error catches, which I almost never use.

When I code in Java, error handling is extremely encouraged (partially because it's in a classroom environment). However, I've mostly found little use for exceptions, as I tend to build a lot of adaptability into my code so it can deal with problems by its very nature (for instance, the strategic placement of conditional statements).

I guess this is almost an issue about programming in general, but I was just curious as to how everyone else deals with their errors in VBA, and how they prefer to see them dealt with.
 
Yeah, the stuff you described is what I was saying I added. For the one sub I've been using as an example here I'm not letting them browse for files, since like 20 are referenced. But two days ago they would've gotten Subscript Out of Range or Global Reference Failed, then half of the files would've been left open and their report would be half made. Today they get "Necessary file (filename) is missing. Please add it to this directory (directory) and run the macro again", and everything is closed without changes saved. Oh, and I have a catch-all that reports "Something has gone horribly wrong." That's just to mess with these users though :LOL:
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Oh, and I have a catch-all that reports "Something has gone horribly wrong." That's just to mess with these users though
{GRIN}

So, two-pronged error handling! Exit gracefully and let them know whose fault it was ;)

Denis
 
Upvote 0

Forum statistics

Threads
1,215,086
Messages
6,123,035
Members
449,092
Latest member
ikke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top