我有一个名为TryMe
try catch 块并捕获他的异常的方法。
我从另一个班级给他打电话,但是当发生异常时,它不会停止代码执行。
例子:
public void TryMe()
{
try
{
SomeMethod();
}
catch(Exception exception){
MessageBox.Show(exception.Message);
}
}
//Method calling
Actions CAactions = new Actions();
CActions.TryMe();
///////////////////////////////////
//If exception is handled it should stop to here.
this.Hide();
FormActions FormActions = new FormActions();
方法定义在类文件中。方法调用是windows形式的。
问题是它只显示消息框并且代码继续执行。
我想在异常捕获后停止代码而不是隐藏表单。如果一切正常,它应该隐藏它。
也许我的观念是错误的?