Jar中的Java代码:
public class FatherClass
{
public void throwChildAClassException()
{
throw new FatherClass.ChildAClassException();
}
public class ChildAClassException extends RuntimeException
{
private static final long serialVersionUID = 1L;
}
public class ChildBClassException extends RuntimeException
{
private static final long serialVersionUID = 1L;
}
}
在Xamarin中:
当我调用方法ThrowChildAClassException()
时,它会将基类抛出为RuntimeException
。
↓↓↓代码↓↓↓
try
{
new FatherClass().ThrowChildAClassException()
}
catch(ChildAClassException childAE)
{
// debugged but does not reach here
}
catch(ChildAClassException childBE)
{
// no invoking
}
catch(RuntimeException e)
{
// debugger approaches here. Isn't it wrong or a bug?
}
那么,我怎样才能获得像ChildAClassException
这样的子类?
谢谢,全部。
答案 0 :(得分:0)
由我修复......
try
{
new FatherClass().ThrowChildAClassException()
}
catch(RuntimeException e)
{
// Android.Runtime.Extensions.JavaCast<ChildAClassException>(e);
// Android.Runtime.Extensions.JavaCast<ChildBClassException>(e);
string currentExceptionSimpleName = e.Class.SimpleName;
string classChildAClassExceptionSimpleName = typeof(ChildAClassException).Name;
string classChildBClassExceptionSimpleName = typeof(ChildBClassException).Name;
if(currentExceptionSimpleName == classChildAClassExceptionSimpleName)
{
// ...
}
else if(currentExceptionSimpleName == classChildBClassExceptionSimpleName)
{
// ...
}
}