以下是我的一段代碼:\如何從異常中獲取消息?
public void LoadProjectFile(String Filename) throws Exception
{
// m_Renderer.m_Project=new Project();
refresh_project();
m_Renderer.m_SelectedProjectPath = Filename;
try {
m_Renderer.m_Project.load_file(Filename);
}
catch (Exception e)
{
//Exception a = e.getMessage();
String a= e.getMessage();
throw new Exception(a);
}
//AppFuncs.m_GisProject=m_Renderer.m_Project;
}
try
{
Map.this.mGLView.LoadProjectFile(AppFuncs.g_path);
Map.this.mGLView.requestRender();
}
catch (Exception e)
{
br=1;
b=e.getMessage();
}
加載的項目文件拋出我在地圖類收到異常。 This exception contains message: Java.lang.exception: java.lang.exception: file not found.
我只想顯示"File not found"
消息。所以我應該如何從異常中獲取此消息?
看一看這個,它正是你要找的 http://stackoverflow.com/questions/9017820/exception-getmessage-output-without-class-name –