JPA规范区分系统异常和应用程序异常.我对绘制线的确切位置感到有点困惑.我的猜测:
应用程序异常是代码使用的代码或库显式或隐式抛出的异常.
系统异常可能是持久性提供程序抛出的异常.它当然包含所有子类javax.persistence.PersistenceException.
EJBException吗?如何使用ApplicationException注释来影响行为?我还没有看到它被使用过.
我有一个winforms应用程序.在开发模式下,从Visual Studio .NET 2003进行调试时(是的,我知道它已经过时,但这是一个遗留项目),当我尝试打开一个新表单时出现此错误.为了打开一个新表单,我得到一个表单实例,然后我调用ShowDialog()方法,例如:
frmTest test = new frmTest(here my parameters);
test.ShowDialog();
Run Code Online (Sandbox Code Playgroud)
如果我按F11(踏入),调试它没有崩溃的时候,但如果在我实例的形式行我按F10进入下一行,也就是test.ShowDialog(),那么它崩溃显示此错误.
完整的消息错误是:
"System.drawing.dll中发生了'System.ApplicationException'类型的未处理异常.附加信息:试图释放不属于该进程的互斥"
我翻译了最后一部分:附加信息......因为它出现在西班牙语中.
我用参数实例化的表单,它的构造函数,包括初始化一些变量,例如:
public frmTest(string param1, string param2)
{
InitializeComponent();
this.param1 = param1;
this.param2 = param2;
}
private void frmTest_Load(object sender, EventArgs e)
{
// here I call a remote webservice asynchronously.
}
Run Code Online (Sandbox Code Playgroud)
我的表格"frmTest"还有四个图片框,一个标签和一个按钮.其中三个图片框包含一个png图像(它是在设计时通过Image属性分配的),最后一个图片框包含一个动画gif,也是通过Image属性在设计时加载的.可能由于这些图像而发生错误?
在我的文件存储库中,我将在InsertFile()调用该方法时抛出以下异常:
目前我正在抛出ApplicationException相关信息:
public void InsertFile(HttpPostedFile uploadedFile)
{
if (uploadedFile.ContentLength > FileSizeLimit)
{
throw new ApplicationException("File size limit exceeded.");
}
if (uploadedFile.ContentLength + FileStorageUsage > FileStorageCapacity)
{
throw new ApplicationException("File storage capacity exceeded.");
}
// ...
}
Run Code Online (Sandbox Code Playgroud)
问题:
我应该在这里使用更好的异常类吗?
或者我应该通过派生来创建自己的自定义异常ApplicationException?
我想知道ApplicationException当用户违反某些业务规则时,是否建议使用它来返回应用程序错误.例如:
public void validate(string name, string email)
{
int count1 = (from p in context.clients
where (p.name == clients.name)
select p).Count();
if (count1 > 0)
throw new ApplicationException("Your name already exist in the database");
int count2 = (from p in context.clients
where (p.email == clients.email)
select p).Count();
if (count2 > 0)
throw new ApplicationException("Your e-mail already exist in the database");
}
Run Code Online (Sandbox Code Playgroud)
这是一个好的或坏的策略?如果不是,那会是更好的方法?