This project is read-only.
Using ArgumentException and exception patterns

Category:
Exceptions
Description: Raising an 'ArgumentException' exception, and filtering for .NET exceptions
Code:
let ExceptionSample4() =
try
printfn "About to raise an ArgumentException exception..."
if DateTime.Now.DayOfWeek = DayOfWeek.Tuesday then
raise (new System.ArgumentException("Not today, it's Tuesday"))
else
raise (new System.ApplicationException("Hey, it's not Tuesday..."))
with
| :? System.ArgumentException as e ->
printfn "Caught an ArgumentException, e.Message = %s" e.Message
| :? System.ApplicationException as e ->
printfn "Caught an ApplicationException, e.Message = %s" e.Message
| _ ->
printfn "Some other exception was caught"

//--------------------------------------------------------

Execution Result:
About to raise an ArgumentException exception...
Caught an ApplicationException, e.Message = Hey, it's not Tuesday...

Last edited Sep 14, 2011 at 3:43 AM by ttliu2000, version 1

Comments

No comments yet.