我有意为特定情况抛出异常,但我希望隐式地以字符串格式获取错误消息。我知道以下异常的其中一个重载是 string message
,但我该如何访问该字符串?
以下是相关代码片段:
string errMsg;
private void Compress()
{
if (sourcePath.EndsWith(".zip"))
{
throw new FileLoadException
("File already compressed. Unzip the file and try again.");
errMsg = //I want the above string here
}
}