1+ namespace JavaScriptEngineSwitcher . Core . Helpers
2+ {
3+ using System ;
4+ using System . Text ;
5+
6+ using Resources ;
7+ using Utilities ;
8+
9+ /// <summary>
10+ /// JavaScript runtime error helpers
11+ /// </summary>
12+ public static class JsRuntimeErrorHelpers
13+ {
14+ /// <summary>
15+ /// Generates a detailed error message
16+ /// </summary>
17+ /// <param name="jsRuntimeException">JavaScript runtime exception</param>
18+ /// <returns>Detailed error message</returns>
19+ public static string Format ( JsRuntimeException jsRuntimeException )
20+ {
21+ var errorMessage = new StringBuilder ( ) ;
22+ errorMessage . AppendFormatLine ( "{0}: {1}" , Strings . ErrorDetails_Message ,
23+ jsRuntimeException . Message ) ;
24+ errorMessage . AppendFormatLine ( "{0}: {1}" , Strings . ErrorDetails_EngineName ,
25+ jsRuntimeException . EngineName ) ;
26+ if ( ! string . IsNullOrWhiteSpace ( jsRuntimeException . ErrorCode ) )
27+ {
28+ errorMessage . AppendFormatLine ( "{0}: {1}" , Strings . ErrorDetails_ErrorCode ,
29+ jsRuntimeException . ErrorCode ) ;
30+ }
31+ if ( ! string . IsNullOrWhiteSpace ( jsRuntimeException . Category ) )
32+ {
33+ errorMessage . AppendFormatLine ( "{0}: {1}" , Strings . ErrorDetails_Category ,
34+ jsRuntimeException . Category ) ;
35+ }
36+ if ( jsRuntimeException . LineNumber > 0 )
37+ {
38+ errorMessage . AppendFormatLine ( "{0}: {1}" , Strings . ErrorDetails_LineNumber ,
39+ jsRuntimeException . LineNumber . ToString ( ) ) ;
40+ }
41+ if ( jsRuntimeException . ColumnNumber > 0 )
42+ {
43+ errorMessage . AppendFormatLine ( "{0}: {1}" , Strings . ErrorDetails_ColumnNumber ,
44+ jsRuntimeException . ColumnNumber . ToString ( ) ) ;
45+ }
46+ if ( ! string . IsNullOrWhiteSpace ( jsRuntimeException . SourceFragment ) )
47+ {
48+ errorMessage . AppendFormatLine ( "{1}:{0}{0}{2}" , Environment . NewLine ,
49+ Strings . ErrorDetails_SourceFragment ,
50+ jsRuntimeException . SourceFragment ) ;
51+ }
52+
53+ return errorMessage . ToString ( ) ;
54+ }
55+ }
56+ }
0 commit comments