Skip to content

Commit

Permalink
Fsdk/Misc: add better assert function
Browse files Browse the repository at this point in the history
Debug.Assert is better than failwith in the sense that its
failure cannot be captured by a try-with block, however
failwith is better than Debug.Assert because it also fails
in !DEBUG (fail fast is better). So here we create the best
of both worlds.
  • Loading branch information
knocte committed Jul 5, 2023
1 parent bb1cede commit 7acb7a5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Fsdk/Misc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open System
open System.IO
open System.Text
open System.Reflection
open System.Diagnostics
open System.Linq

#if LEGACY_FRAMEWORK
Expand Down Expand Up @@ -900,3 +901,9 @@ module Misc =
let ExtractEmbeddedResourceFileContents(resourceName: string) =
let assembly = Assembly.GetCallingAssembly()
ExtractEmbeddedResourceFileContentsFromAssembly resourceName assembly

let BetterAssert (expr: bool) (errMsg: string) =
Debug.Assert(expr, errMsg)

if not expr then
failwith errMsg

0 comments on commit 7acb7a5

Please sign in to comment.