Stack trace missing with custom exception

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;
}
 
S

sloan

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)

{

}

}
 
C

Chris Fellows

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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top