我想在Catch {}中放一个方法,将错误发送到我的“.log”文件。 我喜欢把页面的地址和错误发生的方法。所以我希望你帮助我,告诉我如何定义“strErrorPath”并将其作为我的方法输入。
static Handler handler=new Handler();
...
public void startTimer(long duration, PageAdapter.TheViewHolder holder){
...
handler.postDelayed(new timer(duration, holder),0);//Call the class to start the Timer
}
static class timer implements Runnable {
volatile PageAdapter.TheViewHolder holder;
volatile long duration;
public timer(long duration, PageAdapter.TheViewHolder holder){
this.holder = holder;
this.duration = duration;
}
@Override
public void run() {
...
duration -= 1000; //Remove 1 Seconds
handler.postDelayed(this,1000); //Delay in 1 Seconds
EventBus.getDefault().post(new PageAdapter.CounterTextPojo(duration, holder)); //Update Textview using EventBus function
}
}
答案 0 :(得分:0)
只需使用ex.Source
和ex.StackTrace
,他们就会显示有关例外的有用信息。
您可以阅读有关StackTrace
Here
答案 1 :(得分:0)
另一种选择是使用来电者信息属性。 以下是参考:MSDN : Caller Information (C#)
public static void Log(string errMsg,
[System.Runtime.CompilerServices.CallerMemberName] string member = "",
[System.Runtime.CompilerServices.CallerFilePath] string filePath = "",
[System.Runtime.CompilerServices.CallerLineNumber] int sourceLine = 0)
{
//log somthing...
}
答案 2 :(得分:0)
也许你可以试试:
try {
$response = $client->request('PUT', $theUrl);
$theBody = $response->getBody();
} catch (RequestException $e) {
echo $e;
}