J
John A Grandy
I am finding that when using a singleton to instantiate a class and a custom
exception is thrown in the constructor of the class being instantiated , in
the code that calls the singleton the original exception is not thrown.
Rather , a generic type initialization exception is thrown for the
singleton.
Does anyone know why this is ?
So,
public class MyClassInitException : Exception
{
public MyClassInitException( string message ) : base( message ) { }
}
public class MyClass
{
public MyClass()
{
// something goes wrong ...
// throw MyClassInitException
}
}
public class MyClassSingleton
{
private static MyClass _instance = new MyClass();
public MyClass Instance()
{
return _instance;
}
}
//calling code :
MyClass myClass = MyClassSingleton.Instance();
// exception is thrown "The type initializer for MyClassSingleton threw an
exception."
exception is thrown in the constructor of the class being instantiated , in
the code that calls the singleton the original exception is not thrown.
Rather , a generic type initialization exception is thrown for the
singleton.
Does anyone know why this is ?
So,
public class MyClassInitException : Exception
{
public MyClassInitException( string message ) : base( message ) { }
}
public class MyClass
{
public MyClass()
{
// something goes wrong ...
// throw MyClassInitException
}
}
public class MyClassSingleton
{
private static MyClass _instance = new MyClass();
public MyClass Instance()
{
return _instance;
}
}
//calling code :
MyClass myClass = MyClassSingleton.Instance();
// exception is thrown "The type initializer for MyClassSingleton threw an
exception."