87ea6c6b0acacd5ee14176c87c0542ba9d2c82ce
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Xaml / XamlParseException.cs
1 using System;
2 using System.ComponentModel;
3 using System.Diagnostics;
4 using System.Text;
5 using System.Xml;
6
7 namespace Tizen.NUI.Xaml
8 {
9     /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
10     [EditorBrowsable(EditorBrowsableState.Never)]
11     public class XamlParseException : Exception
12     {
13         readonly string _unformattedMessage;
14
15         static private StringBuilder GetStackInfo()
16         {
17             StringBuilder ret = new StringBuilder("\nStack:\n");
18
19             StackTrace st = new StackTrace();
20
21             for (int i = 2; i < st.FrameCount; i++)
22             {
23                 StackFrame sf = st.GetFrame(i);
24                 ret.AppendFormat("File:{0}, Method:{1}, Line:{2}\n", sf.GetFileName(), sf.GetMethod().Name, sf.GetFileLineNumber());
25             }
26
27             return ret;
28         }
29
30         /// <summary> Initializes a new instance. </summary>
31         [EditorBrowsable(EditorBrowsableState.Never)]
32         public XamlParseException()
33         {
34         }
35
36         /// <summary> Initializes a new instance with message. </summary>
37         [EditorBrowsable(EditorBrowsableState.Never)]
38         public XamlParseException(string message) : base(message)
39         {
40            _unformattedMessage = message;
41         }
42
43         /// <summary> Initializes a new instance with message and inner exception. </summary>
44         [EditorBrowsable(EditorBrowsableState.Never)]
45         public XamlParseException(string message, Exception innerException = null) : base(message, innerException)
46         {
47            _unformattedMessage = message;
48         }
49
50         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
51         [EditorBrowsable(EditorBrowsableState.Never)]
52         public XamlParseException(string message, IXmlLineInfo xmlInfo, Exception innerException = null) : base(FormatMessage(message + GetStackInfo(), xmlInfo), innerException)
53         {
54             _unformattedMessage = message;
55             XmlInfo = xmlInfo;
56         }
57
58         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
59         [EditorBrowsable(EditorBrowsableState.Never)]
60         public IXmlLineInfo XmlInfo { get; private set; }
61
62         internal string UnformattedMessage
63         {
64             get { return _unformattedMessage ?? Message; }
65         }
66
67         static string FormatMessage(string message, IXmlLineInfo xmlinfo)
68         {
69             if (xmlinfo == null || !xmlinfo.HasLineInfo())
70                 return message;
71             return string.Format("Position {0}:{1}. {2}", xmlinfo.LineNumber, xmlinfo.LinePosition, message);
72         }
73     }
74 }