Stack trace missing with custom exception

  • Thread starter Thread starter Chris Fellows
  • Start date Start date
C

Chris Fellows

My C# (VS 2005) application has a custom exception which, when examined,
does not show a stack trace either in debug or as an executable. I'm using
the StackTrace class and passing the custom exception to the constructor.
The exception's StackTrace property is also null.

The exception is derived from System.Exception and every class constructor
does use the 'base' keyword to set the inner exception & message. The
constructor does not contain any code within the {} brackets.

Can someone help me out as to what might be wrong?

An example:

try
{
// Do something that throws an exception
}
catch (System.Exception exception)
{
MyCustomException myException = new MyCustomException("Custom
exception", exception)
StackTrace stackTrace = new StackTrace(myException, true);
throw myException;
}
 
MyCustomException


We need to see the definition of MyCustomException

Here is a sample:
[Serializable()]

public class MyCustomException : System.Exception

{

public MyCustomException()

: base("An ImageViewerLoadException has occurred")

{

}



public MyCustomException(string message)

: base(message)

{

}



public MyCustomException(string message, Exception innerException)

: base(message, innerException)

{

}

}
 
Your example is identical to what I'm using.

sloan said:
MyCustomException


We need to see the definition of MyCustomException

Here is a sample:
[Serializable()]

public class MyCustomException : System.Exception

{

public MyCustomException()

: base("An ImageViewerLoadException has occurred")

{

}



public MyCustomException(string message)

: base(message)

{

}



public MyCustomException(string message, Exception innerException)

: base(message, innerException)

{

}

}






Chris Fellows said:
My C# (VS 2005) application has a custom exception which, when examined,
does not show a stack trace either in debug or as an executable. I'm
using the StackTrace class and passing the custom exception to the
constructor. The exception's StackTrace property is also null.

The exception is derived from System.Exception and every class
constructor does use the 'base' keyword to set the inner exception &
message. The constructor does not contain any code within the {}
brackets.

Can someone help me out as to what might be wrong?

An example:

try
{
// Do something that throws an exception
}
catch (System.Exception exception)
{
MyCustomException myException = new MyCustomException("Custom
exception", exception)
StackTrace stackTrace = new StackTrace(myException, true);
throw myException;
}
 
Back
Top