2003-03-24 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mcs / class / System.Web / System.Web / HtmlizedException.cs
1 //
2 // System.Web.HtmlizedException
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
6 //
7 // (C) 2003 Ximian, Inc (http://www.ximian.com)
8 //
9
10 using System;
11 using System.IO;
12 using System.Text;
13
14 namespace System.Web
15 {
16         internal abstract class HtmlizedException : Exception
17         {
18                 protected HtmlizedException ()
19                 {
20                 }
21
22                 protected HtmlizedException (string message)
23                         : base (message)
24                 {
25                 }
26
27                 protected HtmlizedException (string message, Exception inner)
28                         : base (message, inner)
29                 {
30                 }
31
32                 public abstract string Title { get; }
33                 public abstract string Description { get; }
34                 public abstract string ErrorMessage { get; }
35                 public abstract string FileName { get; }
36                 public abstract StringReader SourceError { get; }
37                 public abstract int SourceErrorLine { get; }
38                 public abstract TextReader SourceFile { get; }
39
40                 public bool HaveSourceError {
41                         get { return SourceError != null; }
42                 }
43
44                 public bool HaveSourceFile {
45                         get { return SourceFile != null; }
46                 }
47
48                 internal static string GetErrorLines (TextReader reader, int line, out int errorLine)
49                 {
50                         int firstLine = (line > 2) ? (line - 2) : line;
51                         int lastLine = (line >= 0) ? (firstLine + 2) : Int32.MaxValue;
52                         errorLine = (line > 2) ? line : 1;
53                         int current = 0;
54                         string s;
55
56                         while ((s = reader.ReadLine ()) != null && current != firstLine)
57                                 current++;
58
59                         if (s == null)
60                                 return "Cannot read error line.";
61
62                         StringBuilder builder = new StringBuilder ();
63                         do {
64                                 builder.Append (s + '\n');
65                                 current++;
66                         } while (current < lastLine && (s = reader.ReadLine ()) != null);
67
68                         return builder.ToString ();
69                 }
70         }
71 }
72