Evenementer
Mar 17, 11 PM - Mar 21, 11 PM
Maacht mat bei der Meetup-Serie, fir skaléierbar KI-Léisungen op Basis vu realistesche Benotzungsfäll mat aneren Entwéckler an Experten ze bauen.
Elo umellenDëse Browser gëtt net méi ënnerstëtzt.
Upgrat op Microsoft Edge fir vun de Virdeeler vun leschten Eegeschaften, Sécherheetsupdaten, an techneschem Support ze profitéieren.
There are two categories of exceptions in F#: .NET exception types and F# exception types. This topic describes how to define and use F# exception types.
exception exception-type of argument-type
In the previous syntax, exception-type is the name of a new F# exception type, and argument-type represents the type of an argument that can be supplied when you raise an exception of this type. You can specify multiple arguments by using a tuple type for argument-type.
A typical definition for an F# exception resembles the following.
exception MyError of string
You can generate an exception of this type by using the raise
function, as follows.
raise (MyError("Error message"))
You can use an F# exception type directly in the filters in a try...with
expression, as shown in the following example.
exception Error1 of string
// Using a tuple type as the argument type.
exception Error2 of string * int
let function1 x y =
try
if x = y then raise (Error1("x"))
else raise (Error2("x", 10))
with
| Error1(str) -> printfn "Error1 %s" str
| Error2(str, i) -> printfn "Error2 %s %d" str i
function1 10 10
function1 9 2
The exception type that you define with the exception
keyword in F# is a new type that inherits from System.Exception
.
Feedback zu .NET
.NET ass en Open-Source-Projet. Wielt e Link, fir Feedback ze ginn:
Evenementer
Mar 17, 11 PM - Mar 21, 11 PM
Maacht mat bei der Meetup-Serie, fir skaléierbar KI-Léisungen op Basis vu realistesche Benotzungsfäll mat aneren Entwéckler an Experten ze bauen.
Elo umellen