2 * Copyright(c) 2022 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.ComponentModel;
20 using System.Diagnostics;
24 namespace Tizen.NUI.Xaml
26 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
27 [EditorBrowsable(EditorBrowsableState.Never)]
28 public class XamlParseException : Exception
30 readonly string unformattedMessage;
32 static private StringBuilder GetStackInfo()
34 StringBuilder ret = new StringBuilder("\nStack:\n");
36 StackTrace st = new StackTrace();
38 for (int i = 2; i < st.FrameCount; i++)
40 StackFrame sf = st.GetFrame(i);
41 ret.AppendFormat("File:{0}, Method:{1}, Line:{2}\n", sf.GetFileName(), sf.GetMethod().Name, sf.GetFileLineNumber());
47 /// <summary> Initializes a new instance. </summary>
48 [EditorBrowsable(EditorBrowsableState.Never)]
49 public XamlParseException()
53 /// <summary> Initializes a new instance with message. </summary>
54 [EditorBrowsable(EditorBrowsableState.Never)]
55 public XamlParseException(string message) : base(message)
57 unformattedMessage = message;
60 /// <summary> Initializes a new instance with message and inner exception. </summary>
61 [EditorBrowsable(EditorBrowsableState.Never)]
62 public XamlParseException(string message, Exception innerException = null) : base(message, innerException)
64 unformattedMessage = message;
67 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
68 [EditorBrowsable(EditorBrowsableState.Never)]
69 public XamlParseException(string message, IXmlLineInfo xmlInfo, Exception innerException = null) : base(FormatMessage(message + GetStackInfo(), xmlInfo), innerException)
71 unformattedMessage = message;
75 internal XamlParseException(string message, IServiceProvider serviceProvider, Exception innerException = null)
76 : this(message, GetLineInfo(serviceProvider), innerException)
80 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
81 [EditorBrowsable(EditorBrowsableState.Never)]
82 public IXmlLineInfo XmlInfo { get; private set; }
84 internal string UnformattedMessage
86 get { return unformattedMessage ?? Message; }
89 static string FormatMessage(string message, IXmlLineInfo xmlinfo)
91 if (xmlinfo == null || !xmlinfo.HasLineInfo())
93 return string.Format("Position {0}:{1}. {2}", xmlinfo.LineNumber, xmlinfo.LinePosition, message);
97 static IXmlLineInfo GetLineInfo(IServiceProvider serviceProvider)
98 => (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) is IXmlLineInfoProvider lineInfoProvider) ? lineInfoProvider.XmlLineInfo : new XmlLineInfo();