我想要一些关于建立已知错误的建议。假设我有一个Windows窗体,它需要设置对象中图像的源路径。必须是:
- A valid path
- An image
- A PNG
- 32 x 32 in size
- No transparency
关于捕获错误的问题是,我希望类尽可能多地处理错误,而不是Windows窗体。
所以我们假设我曾经:
Public Class MyImage
Public Property SourcePath As String
End Class
和
Sub TestImage()
Dim imgPath As New MyImage
Try
imgPath.SourcePath = "C:My Documentsimage001.png".
Catch ex As Exception
MsgBox(ex)
End Try
End Sub
SourcePath
should be a string path that points to a valid image file, that is a png, that is 32x32 和 has no transparency. If it is not one or more of those, I just want the ex
to report back what error(s) are there (like "The image is not 32x32" or "The image contains transparency, which is should not. And it also is not 32x32.). How can I create my own Exceptions for the property SourcePath
above?
除此之外,假设我有上面所有相同的要求,但我要求SourcePath
上的图像大小为48x48,而不是32x32。有没有办法对此进行自定义?
Thx提前