You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/fsharp-cheatsheet.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -689,7 +689,7 @@ See [Pattern Matching (MS Learn)](https://learn.microsoft.com/en-us/dotnet/fsha
689
689
690
690
## Try..With
691
691
692
-
An illustrative example with: custom F# exception creation, all exception aliases, `raise()` usage, and an exhaustive demonstration of the exception handler patterns:
692
+
An illustrative example with: custom F# exception creation, all exception aliases, `raise` usage, and an exhaustive demonstration of the exception handler patterns:
693
693
694
694
```fsharp
695
695
open System
@@ -702,26 +702,26 @@ try
702
702
invalidArg "ArgumentName" "Message" // throws a System.ArgumentException
703
703
invalidOp "Message" // throws a System.InvalidOperation
704
704
705
-
raise(NotImplementedException("Message")) // throws a .NET exception (2)
706
-
raise(MyException(0, "Message")) // throws an F# exception (2)
705
+
raise(NotImplementedException("Message")) // throws a .NET exception (2)
706
+
raise(MyException(0, "Message")) // throws an F# exception (2)
1. define your own F# exception types with `exception`, a new type that will inherit from `System.Exception`;
720
-
2. use `raise()` to throw an F# or .NET exception;
720
+
2. use `raise` to throw (an F# or .NET) exception;
721
721
3. the entire `try..with` expression must evaluate to the same type, in this example: bool;
722
722
4.`ArgumentNullException` inherits from `ArgumentException`, so `ArgumentException` must follow after;
723
723
5. support for `when` guards;
724
-
6. use `reraise()` to re-throw an exception; works with both .NET and F# exceptions
724
+
6. use `reraise()` to re-throw the exception being handled (retaining the original throw site in the stack trace); works with both .NET and F# exceptions
725
725
726
726
The difference between F# and .NET exceptions is how they are created and how they can be handled.
0 commit comments