Information Technology Reference
In-Depth Information
public MyAssemblyException( string s,
Exception e) :
base (s, e)
{
}
protected MyAssemblyException(
SerializationInfo info, StreamingContext cxt) :
base (info, cxt)
{
}
}
The constructors that take an exception parameter deserve a bit more dis-
cussion. Sometimes, one of the libraries you use generates an exception.
The code that called your library will get minimal information about the
possible corrective actions when you simply pass on the exceptions from
the utilities you use:
public double DoSomeWork()
{
// This might throw an exception defined
// in the third party library:
return ThirdPartyLibrary .ImportantRoutine();
}
Yo u s h o u l d p r o v i d e y o u r o w n l i b r a r y ' s i n f o r m a t i o n w h e n y o u g e n e r a t e
the exception. Throw your own specific exception and include the origi-
nal exception as its InnerException property. You can provide as much
extra information as you can generate:
public double DoSomeWork()
{
try {
// This might throw an exception defined
// in the third party library:
return ThirdPartyLibrary .ImportantRoutine();
} catch (ThirdPartyException e)
{
string msg =
string .Format( "Problem with {0} using library" ,
ToString());
 
Search WWH ::




Custom Search