4

I'd like to create a custom exception with a constructor taking some context and building its message itself. In Java, that would look like (see how to create custom exception with a number in constructor in Java)

public MyException(String message, IContext context){
    super(message + " " + context.someData);
}

In C# however, the compiler tells me that base() is not valid in this context.

public MyException(IContext context)
{
    base(String.Format("Context is: {0}", context));
}

What's wrong?

0

1 Answer 1

3

The C# syntax is:

public MyException(IContext context)
    : base(String.Format("Context is: {0}", context))
{
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.