I want to make a custom Exception in C#, but in theory I do need to do a little parsing first before I can make a human readable ExceptionMessage.
The problem is that th
I think the problem may be with the Visual Studio debugger. I got the same exact results you got using the debugger, but when I print the message instead:
class CustomException : Exception {
public CustomException(dynamic json)
: base("Plep") {
_Message = json.message;
}
public override string Message {
get { return _Message; }
}
private string _Message;
}
class Program {
static void Main(string[] args) {
try {
throw new CustomException(new { message = "Show this message" });
} catch (Exception ex) {
Console.WriteLine(ex.Message);
}
}
}
I get the expected "Show this message"
.
If you put a breakpoint where the Exception is caught, the debugger does show you the correct message.