> ## Content Index
> Fetch the complete content index at: https://nolongerset.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Five Ways to Turn Logic Errors into Runtime Errors in VBA
- URL: https://nolongerset.com/turn-logic-errors-into-runtime-errors/
- Published: 2023-04-17T23:55:29.000Z
- Updated: 2026-05-08T12:50:26.000Z
- Description: Runtime errors are cheaper and easier to fix than logic errors. Here are five ways to make that happen.
- Author: Mike Wolfe
- Tags: Defensive Programming, Bug Types, VBA, #Import 2026-05-20 02:59

Runtime errors are better than logic errors.

[Some Bugs are Better than OthersNot all bugs are created equal. Avoid the expensive ones by making more of the ones that are easy to find and fix.![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/03/car-2122580_1920.jpg)](https://nolongerset.com/some-bugs-are-better-than-others/)

That's all well and good, but it leads to an obvious follow up question. How does one turn a logic error into a runtime error?

Here is a list of techniques you can use to turn a logic error into a runtime error:

1. Guard Clauses
2. Double Checks
3. Avoid Excessive Error Handling
4. Throw Errors via Case Else
5. Use the "Unset" Enum

Let's explore each strategy in more detail.

### Guard Clauses

Use guard clauses to validate program state at the start of a procedure and exit or throw an error if there is a problem with procedure inputs or external dependencies. When combined with my [custom Throw() function](https://nolongerset.com/throwing-errors-in-vba/) and [vbWatchdog error handling](https://nolongerset.com/error-handling-evolution/), guard clauses are a low-friction way to guard against potential logic errors.

[Guard ClausesGuard clauses are one of my favorite low-friction defensive programming tools.![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2023/01/Guard-Clauses-1.jpeg)](https://nolongerset.com/guard-clauses/)

### Double Checks

For critical calculations, use two different algorithms to arrive at the value and throw an error if the independent calculations produce different values.

[5 Ways to Reduce Logic Errors Using Automated Double-ChecksIdentify the critical functions in your application. Then, apply one or more of these techniques to ensure that if they break, someone will notice.![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/10/forest-climbing-park-931256_1920.jpg)](https://nolongerset.com/4-ways-to-reduce-logic-errors-using-automated-double-checks/)

### Avoid Excessive Error Handling

Not every routine requires an error handler. Sometimes, if you are calling a procedure as part of a larger routine, the best way to "handle" an error is to let it bubble up to the calling routine.

[Why “Add an Error Handler to Every Routine” is Bad AdviceFor every complex problem, there is an answer that is clear, simple, and wrong.(Shocking, I know.)![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/11/lemur-3295891_1920.jpg)](https://nolongerset.com/handling-errors/)

### Throw Errors via Case Else

Every Select Case statement should include a Case Else, even if you have covered all the possible code paths. Because, in that situation, you've only covered all of the possible code paths that you know about (or that exist at the time). If you don't think you need the Case Else, add one anyway and raise an error if the code ever reaches that path.

### Use the "Unset" Enum

Enums in VBA are little more than glorified Long datatypes. That means that they have a default value of 0, which just happens to match the default value of the first item in an enum. Thus, if a variable based on an enum has a numeric value of 0, there is no reliable way to know whether that value was set explicitly or is simply the implicit default value. If we make logic decisions based on the faulty assumption that every enum has been explicitly set, we introduce the possibility of a logic error. To avoid this potential problem, we can make the first item in every enum an "Unset" value. This allows us to know with certainty whether an enum variable has been explicitly set or only reflects its default value.

[The “Unset” Enum ItemThis simple technique is a foolproof way to avoid the sort of logic bug that can live undetected in your codebase for years.![](https://nolongerset.com/favicon.png)No Longer SetMike Wolfe![](https://storage.ghost.io/c/eb/d7/ebd732c1-5f03-4f07-b386-5d08557e15c9/content/images/2021/07/canary-4248324_1920.jpg)](https://nolongerset.com/unset-enum-item/)