1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Framework
19 using System
.Runtime
.Serialization
;
22 /// Thrown when a controller is not found.
25 public class ControllerNotFoundException
: ApplicationException
27 private readonly String area
, controller
;
30 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
32 /// <param name="message">The message.</param>
33 public ControllerNotFoundException(string message
) : base(message
)
38 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
40 /// <param name="area">The area.</param>
41 /// <param name="controller">The controller.</param>
42 public ControllerNotFoundException(String area
, String controller
) : base(BuildExceptionMessage(area
, controller
))
47 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
49 /// <param name="area">The area.</param>
50 /// <param name="controller">The controller.</param>
51 /// <param name="innerException">The inner exception.</param>
52 public ControllerNotFoundException(String area
, String controller
, Exception innerException
)
53 : base(BuildExceptionMessage(area
, controller
), innerException
)
58 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
60 /// <param name="url">The URL.</param>
61 public ControllerNotFoundException(UrlInfo url
) : this(url
.Area
, url
.Controller
)
66 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
68 /// <param name="url">The URL.</param>
69 /// <param name="innerException">The inner exception.</param>
70 public ControllerNotFoundException(UrlInfo url
, Exception innerException
)
71 : this(url
.Area
, url
.Controller
, innerException
)
76 /// Gets the area name.
78 /// <value>The area name.</value>
85 /// Gets the controller name.
87 /// <value>The controller name.</value>
88 public String Controller
90 get { return controller; }
93 #region Serialization Support
96 /// Initializes a new instance of the <see cref="ControllerNotFoundException"/> class.
98 /// <param name="info">The object that holds the serialized object data.</param>
99 /// <param name="context">The contextual information about the source or destination.</param>
100 protected ControllerNotFoundException(SerializationInfo info
, StreamingContext context
) : base(info
, context
)
102 area
= info
.GetString("rails.area");
103 controller
= info
.GetString("rails.controller");
107 /// When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo"/>
108 /// with information about the exception.
110 /// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
111 /// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
112 /// <exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is a null reference (<see langword="Nothing"/> in Visual Basic).</exception>
113 public override void GetObjectData(SerializationInfo info
, StreamingContext context
)
115 base.GetObjectData(info
, context
);
116 info
.AddValue("rails.area", area
);
117 info
.AddValue("rails.controller", controller
);
123 /// Builds the exception message.
125 /// <param name="area">The area.</param>
126 /// <param name="controller">The controller.</param>
127 /// <returns></returns>
128 private static String
BuildExceptionMessage(String area
, String controller
)
130 StringBuilder sb
= new StringBuilder("Controller not found.");
132 sb
.AppendFormat(" Area: '{0}'", area
);
133 sb
.AppendFormat(" Controller Name: '{0}'", controller
);
135 return sb
.ToString();