diff --git a/src/fable-library-ts/Util.ts b/src/fable-library-ts/Util.ts index 2435c08bf..2ced013e0 100644 --- a/src/fable-library-ts/Util.ts +++ b/src/fable-library-ts/Util.ts @@ -84,6 +84,10 @@ export class Exception { constructor(msg?: string) { this.message = msg ?? ""; } + + toString() { + return this.message; + } } export function isException(x: any) { diff --git a/tests/Js/Main/TypeTests.fs b/tests/Js/Main/TypeTests.fs index 4bbb01375..49d719099 100644 --- a/tests/Js/Main/TypeTests.fs +++ b/tests/Js/Main/TypeTests.fs @@ -1393,6 +1393,15 @@ let tests = | ex -> (false, "unknown", 0.) |> equal (true, "Code: 5", 5.5) + testCase "Exception ToString contains the message" <| fun () -> // See #4197 + let msg = + try + failwith "test message" + "" + with ex -> ex.ToString() + // .NET returns "System.Exception: test message", Fable returns just the message + msg.Contains("test message") |> equal true + testCase "reraise works" <| fun () -> try try