Browse Source

Refactored exception checks in DataProcessing module.

Updated code in script (based on refactoring).
master
Craig Oates 6 years ago
parent
commit
45901cc71f
  1. 6
      WetPancake/DataProcessing.fs
  2. 7
      WetPancake/Script.fsx

6
WetPancake/DataProcessing.fs

@ -12,19 +12,19 @@
let GibberishLevelIsValid gibberishLevel =
match gibberishLevel with
| gibberishLevel when gibberishLevel < 2 || gibberishLevel > 20 ->
raise (new ArgumentException("Invalid argument. Must be between 2 and 20 (inclusive).", "gibberishLevel"))
invalidArg "gibberishLevel" "Invalid argument. Must be between 2 and 20 (inclusive)."
| _ -> ignore
let SentencesIsValid sentences =
match sentences with
| sentences when sentences < 1 ->
raise (ArgumentException("Invalid argument. Must be greater than 0.", "sentences"))
invalidArg "sentences" "Invalid argument. Must be greater than 0."
| _ -> ignore
let FilePathIsValid filePath =
match filePath with
| filePath when Path.GetExtension filePath <> ".txt" ->
raise (ArgumentException("Invalid argument. File must be a .txt file.","filePath"))
invalidArg "filePath" "Invalid argument. File must be a .txt file."
| filePath when not (File.Exists filePath) ->
raise (FileNotFoundException("Unable to find the file at the location specified."))
| _ -> ignore

7
WetPancake/Script.fsx

@ -17,6 +17,7 @@ open DataStructuring
open DataServices
open WetPancake
open System
open System.IO
// Template Files
[<Literal>]
@ -107,10 +108,12 @@ let dp_filePathIsValidException =
let invalidFileType = "C:/notvalid/test.doc"
// Template file paths by the open & load declarations
try
FilePathIsValid TestPost // enter filepath here
FilePathIsValid ConsoleWaterworks // enter filepath here
|> ignore
"No exception thrown"
with :? ArgumentException as ex -> ex.Message
with
| :? ArgumentException as ex -> ex.Message
| :? FileNotFoundException as ex -> ex.Message
// Data Structuring
let ds_map = Map.empty

Loading…
Cancel
Save