@@ -22,14 +22,18 @@ open System
2222/// Represents the style being used to format errors
2323[<RequireQualifiedAccess>]
2424type ErrorStyle =
25- | DefaultErrors
26- | EmacsErrors
27- | TestErrors
28- | VSErrors
29- | GccErrors
25+ | DefaultErrors
26+ | EmacsErrors
27+ | TestErrors
28+ | VSErrors
29+ | GccErrors
3030
3131/// Thrown when we want to add some range information to a .NET exception
32- exception WrappedErrorof exn * range
32+ exception WrappedErrorof exn * range with
33+ override this.Message =
34+ match this:> exnwith
35+ | WrappedError( exn, _) -> " WrappedError(" + exn.Message+ " )"
36+ | _ -> " WrappedError"
3337
3438/// Thrown when immediate, local error recovery is not possible. This indicates
3539/// we've reported an error but need to make a non-local transfer of control.
@@ -39,28 +43,35 @@ exception WrappedError of exn * range
3943/// situations (LazyWithContext) we may need to re-report the original error
4044/// when a lazy thunk is re-evaluated.
4145exception ReportedErrorof exn option with
42- override this.Message =
46+ override this.Message =
47+ let msg = " The exception has been reported. This internal exception should now be caught at an error recovery point on the stack."
4348match this:> exnwith
44- | ReportedError( Some exn) -> exn.Message
45- | _ -> " ReportedError "
49+ | ReportedError( Some exn) -> msg + " Original message: " + exn.Message+ " ) "
50+ | _ -> msg
4651
4752let rec findOriginalException err =
4853match errwith
4954| ReportedError( Some err) -> err
5055| WrappedError( err,_) -> findOriginalException err
5156| _ -> err
5257
53-
5458type Suggestions = unit-> Set< string>
5559
5660let NoSuggestions : Suggestions = fun () -> Set.empty
5761
5862/// Thrown when we stop processing the F# Interactive entry or #load.
59- exception StopProcessingExnof exn option
63+ exception StopProcessingExnof exn option with
64+ override this.Message = " Processing of a script fragment has stopped because an exception has been raised"
65+
66+ override this.ToString () =
67+ match this:> exnwith
68+ | StopProcessingExn( Some exn) -> " StopProcessingExn, originally (" + exn.ToString() + " )"
69+ | _ -> " StopProcessingExn"
70+
71+
6072let (| StopProcessing | _ |) exn = match exnwith StopProcessingExn_ -> Some() | _ -> None
6173let StopProcessing < 'T > = StopProcessingExn None
6274
63- (* common error kinds*)
6475exception NumberedErrorof ( int * string ) * range with // int is e.g. 191 in FS0191
6576override this.Message =
6677match this:> exnwith
@@ -74,26 +85,32 @@ exception Error of (int * string) * range with // int is e.g. 191 in FS0191 /
7485| _ -> " impossible"
7586
7687
77- exception ErrorWithSuggestions of ( int * string ) * range * string * Suggestions with // int is e.g. 191 in FS0191
78- override this.Message =
79- match this:> exnwith
80- | ErrorWithSuggestions ((_, msg),_,_,_ )-> msg
88+ exception InternalError of msg : string * range with
89+ override this.Message =
90+ match this:> exnwith
91+ | InternalError ( msg, m ) -> msg+ m.ToString ()
8192| _ -> " impossible"
8293
83- exception InternalErrorof string * range
8494exception UserCompilerMessageof string * int * range
8595exception LibraryUseOnlyof range
8696exception Deprecatedof string * range
8797exception Experimentalof string * range
8898exception PossibleUnverifiableCodeof range
8999
90- // Range/NoRange Duals
91100exception UnresolvedReferenceNoRangeof (* assemblyname*) string
92101exception UnresolvedReferenceErrorof (* assemblyname*) string * range
93102exception UnresolvedPathReferenceNoRangeof (* assemblyname*) string * (* path*) string
94103exception UnresolvedPathReferenceof (* assemblyname*) string * (* path*) string * range
95104
96105
106+
107+ exception ErrorWithSuggestionsof ( int * string ) * range * string * Suggestions with // int is e.g. 191 in FS0191
108+ override this.Message =
109+ match this:> exnwith
110+ | ErrorWithSuggestions((_, msg),_,_,_) -> msg
111+ | _ -> " impossible"
112+
113+
97114let inline protectAssemblyExploration dflt f =
98115try
99116 f()
@@ -149,9 +166,9 @@ let QuitProcessExiter =
149166type BuildPhase =
150167| DefaultPhase
151168| Compile
152- | Parameter| Parse| TypeCheck
169+ | Parameter| Parse| TypeCheck
153170| CodeGen
154- | Optimize| IlxGen| IlGen| Output
171+ | Optimize| IlxGen| IlGen| Output
155172| Interactive// An error seen during interactive execution
156173
157174/// Literal build phase subcategory strings.
@@ -320,9 +337,7 @@ type internal CompileThreadStatic =
320337module ErrorLoggerExtensions =
321338open System.Reflection
322339
323- // Instruct the exception not to reset itself when thrown again.
324- // Design Note: This enables the compiler to prompt the user to send mail to fsbugs@microsoft.com,
325- // by catching the exception, prompting and then propagating the exception with reraise.
340+ /// Instruct the exception not to reset itself when thrown again.
326341let PreserveStackTrace ( exn ) =
327342try
328343let preserveStackTrace = typeof< System.Exception>. GetMethod( " InternalPreserveStackTrace" , BindingFlags.Instance||| BindingFlags.NonPublic)
@@ -333,7 +348,7 @@ module ErrorLoggerExtensions =
333348()
334349
335350
336- // Reraise an exception if it is one we want to report to Watson.
351+ /// Reraise an exception if it is one we want to report to Watson.
337352let ReraiseIfWatsonable ( exn : exn ) =
338353#if FX_ REDUCED_ EXCEPTIONS
339354 ignore exn
@@ -346,7 +361,7 @@ module ErrorLoggerExtensions =
346361| :? System.IO.IOException-> () // This covers FileNotFoundException and DirectoryNotFoundException
347362| :? System.UnauthorizedAccessException-> ()
348363| Failure_ // This gives reports for compiler INTERNAL ERRORs
349- | :? System.SystemException->
364+ | :? System.SystemException->
350365 PreserveStackTrace( exn)
351366 raise exn
352367| _ -> ()
@@ -362,13 +377,17 @@ module ErrorLoggerExtensions =
362377
363378match exnwith
364379| StopProcessing
365- | ReportedError_ -> raise exn
380+ | ReportedError_ ->
381+ PreserveStackTrace( exn)
382+ raise exn
366383| _ -> x.DiagnosticSink( PhasedDiagnostic.Create( exn, CompileThreadStatic.BuildPhase), true )
367384
368385member x.Warning exn =
369386match exnwith
370387| StopProcessing
371- | ReportedError_ -> raise exn
388+ | ReportedError_ ->
389+ PreserveStackTrace( exn)
390+ raise exn
372391| _ -> x.DiagnosticSink( PhasedDiagnostic.Create( exn, CompileThreadStatic.BuildPhase), false )
373392
374393member x.Error exn =
@@ -389,13 +408,16 @@ module ErrorLoggerExtensions =
389408| :? System.Threading.ThreadAbortException| WrappedError((:? System.Threading.ThreadAbortException),_) -> ()
390409#endif
391410| ReportedError_ | WrappedError( ReportedError_,_) -> ()
392- | StopProcessing| WrappedError( StopProcessing,_) -> raise exn
411+ | StopProcessing| WrappedError( StopProcessing,_) ->
412+ PreserveStackTrace( exn)
413+ raise exn
393414| _ ->
394415try
395416 x.ErrorR( AttachRange m exn) // may raise exceptions, e.g. an fsi error sink raises StopProcessing.
396417 ReraiseIfWatsonable( exn)
397418with
398419| ReportedError_ | WrappedError( ReportedError_,_) -> ()
420+
399421member x.StopProcessingRecovery ( exn : exn ) ( m : range ) =
400422// Do standard error recovery.
401423// Additionally ignore/catch StopProcessing. [This is the only catch handler for StopProcessing].
@@ -408,6 +430,7 @@ module ErrorLoggerExtensions =
408430with
409431| StopProcessing| WrappedError( StopProcessing,_) -> () // catch, e.g. raised by DiagnosticSink.
410432| ReportedError_ | WrappedError( ReportedError_,_) -> () // catch, but not expected unless ErrorRecovery is changed.
433+
411434member x.ErrorRecoveryNoRange ( exn : exn ) =
412435 x.ErrorRecovery exn range0
413436