我需要在 Java 中创建一个异常,该异常的运行方式与以下 C# 相同。
public class ResponseException : Exception
{
internal ResponseException(int statusCode, String StatusCodeDescription, String request, String response)
: base("Returned an error status code " + statusCode.ToString() + " (" + StatusCodeDescription + ") " + response)
{
this.StatusCode = statusCode;
this.StatusCodeDescription = StatusCodeDescription;
this.Request = request;
this.Response = response;
}
public int StatusCode { get; set; }
public String StatusCodeDescription { get; set; }
public String Request { get; set; }
public String Response { get; set; }
}
目前我找不到以这种方式工作的 Java 异常示例。上面的异常就是这样调用的
throw new ResponseException(((int)response[1]),
((String)response[2]), url, ((String)response[0]));
我通读了以下线程,但它们并没有提供太多关于我将如何进行此操作的见解,或者是否有可能。
http://www.java-forums.org/java-lang/7699-how-create-your-own-exception-class.html