有没有办法在不在每个方法中进行显式调用的情况下设置回调(或自动记录)方法参数,条目和出口?我基本上想要将此信息记录到我的记录器类(这是静态的),而不必为每个方法手动执行此操作.
现在我必须在每个方法中调用Logger :: logEntry()和Logger :: logExit()来完成此任务.我很乐意不必这样做:
class TestClass {
public function tester($arg) {
Logger::logEntry();
Logger::info('Parameter $arg => ' . $arg);
// Do some stuff...
Logger::logExit();
}
}
Run Code Online (Sandbox Code Playgroud) 在我的服务器中,我得到了一个异常,我抓住它似乎没问题.
问题是,当我写它的StackTrace时,我得到了BadImageFormatException.
我试过调试服务器.捕获异常时停在断点上,我可以看到它的所有字段,但是在StackTrace中我看到了BadImageFormatException.
有什么想法导致这个问题?
我的服务器细节 -
它是用.NET FW 4用C#编写的.
我也使用用托管C++编写的FrameWork.
我将我的服务器编译为x86平台.并在x64机器上运行服务器.
完整的BadImageFormatException -
System.BadImageFormatException:方法的参数和签名不匹配.在System.Reflection.RuntimeParameterInfo.GetParameters(IRuntimeMethodInfo methodHandle,的MemberInfo构件,签名Sig,的ParameterInfo&returnParameter,布尔fetchReturnParameter)在System.Reflection.RuntimeMethodInfo.GetParameters在System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()()在System.Diagnostics.StackTrace System.Environment.GetStackTrace(Exception e,Boolean needFileInfo)中的System.Environment.GetStackTrace(例外,布局needFileInfo)处的System.Exception.TetTrace(Boolean needFileInfo)处的System.Exception.ToString(布局needFileLineInfo)处的System.Exception.ToString()处于log4net处的.ToString(TraceFormat traceFormat). log4net.ObjectRenderer.RendererMap.FindAndRender(Object obj,TextWriter writer)中的ObjectRenderer.DefaultRenderer.RenderObject(RendererMap rendererMap,Object obj,TextWriter writer)
我有一些错误的代码,我正在使用堆栈跟踪找出行号是什么,但它似乎给了我错误的数字
这是我的代码
Try
Dim query As String = "Select * from table"
Dim ds As DataSet = data.db(query)
Catch e As Exception
Dim st As New StackTrace(True) 'This is the line number it gives me'
Dim sf As StackFrame = st.GetFrame(0)
Response.Write(" Method: " & sf.GetMethod().Name)
Response.Write(" File: " & sf.GetFileName())
Response.Write(" Line Number: " & sf.GetFileLineNumber().ToString())
End Try
Run Code Online (Sandbox Code Playgroud)
它似乎给出了StackTrace启动位置的行号,而不是导致异常的行号
有任何想法吗?
打开一个没有代码的应用程序时,我发生了崩溃.
代码是:
package com.spotsofmagic.spotsofmagic;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Log;
import android.bluetooth.*;
public class CardActivity extends Activity implements OnClickListener {
private static final String TAG = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.card_activity);
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序立即崩溃.堆栈跟踪如下,这对我来说没什么意义:
08-30 22:37:31.698: W/dalvikvm(8852): threadid=1: thread exiting with uncaught exception (group=0x40ceb300)
08-30 22:37:31.718: E/AndroidRuntime(8852): FATAL …Run Code Online (Sandbox Code Playgroud) 我需要将异常记录到数据库中.数据库API声明我可以将值作为ByteBuffer传递或作为byte []数组传递.哪个更有效率?
private final static byte[] getThrowableStackTraceBytes(Throwable throwable) {
StringWriter throwableStackTraceStringWriter = new StringWriter();
throwable.printStackTrace(new PrintWriter(throwableStackTraceStringWriter));
return throwableStackTraceStringWriter.toString().getBytes();
}
Run Code Online (Sandbox Code Playgroud)
与
private final static ByteBuffer getThrowableStackTraceByteBuffer(Throwable throwable) {
ByteArrayOutputStream throwableStackTraceByteArrayOutputStream = new ByteArrayOutputStream();
throwable.printStackTrace(new PrintStream(throwableStackTraceByteArrayOutputStream));
ByteBuffer throwableByteBuffer = ByteBuffer.wrap(throwableStackTraceByteArrayOutputStream.toByteArray());
return throwableByteBuffer;
}
Run Code Online (Sandbox Code Playgroud)
我认为如果我使用ByteBuffer,整体操作会更有效,特别是在它被传递到数据库方法后处理它时.我对吗?
(具体来说,我需要将异常记录到Hypertable中,它使用Thrift Java API.)
这基本上是我先前问题的第2部分,因为我已经根据代码的长度创建了一个新问题.希望我们能够在您的帮助下解决这个问题,我相信我们现在可以通过新信息找到解决方案.
编辑:感谢您的输入.这是pt的链接.1与实际代码:登录功能不起作用.
PS.请不要忘记投票这个问题.
继承人user.rb:
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# name :string(255)
# email :string(255)
# created_at :datetime not null
# updated_at :datetime not null
# encrypted_password :string(255)
# salt :string(255)
#
class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :email, :name, :password, :password_confirmation
email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :name, :presence => true,
:length => { :maximum => 50 }
validates :email, :presence => true,
:format => { …Run Code Online (Sandbox Code Playgroud) 如何显示Ant构建中的所有错误?我想看看其他21个错误.

我需要确定哪个JS文件/行正在修改我页面上的元素.我想在这里找到一个大海捞针.例如,我正在挖掘35个.js文件,以找出哪个文件负责更改网页上的某些文本.这样一个简单的任务似乎太多了.
它可以使用jQuery或javascript以许多不同的方式更改它.方法未知.但它发生在页面加载上.
是否可以在Chrome(开发人员工具)中查看此信息?
与下面的示例类似,当我testSortArrayNull()在名为test的测试类中运行测试用例时ComparatorAbstractTestCase,抛出RuntimeException,生成的堆栈跟踪如下,
这是堆栈跟踪的结果,
testSortArrayNull(org.apache.commons.io.comparator.CompositeFileComparatorTest) Time elapsed: 0.016 sec <<< ERROR!
java.lang.RuntimeException: null
at org.apache.commons.io.comparator.AbstractFileComparator.sort(AbstractFileComparator.java:48)
at org.apache.commons.io.comparator.CompositeFileComparator.sort(CompositeFileComparator.java:45)
at org.apache.commons.io.comparator.ComparatorAbstractTestCase.testSortArrayNull(ComparatorAbstractTestCase.java:96)
...
Run Code Online (Sandbox Code Playgroud)
这是测试类的部分代码ComparatorAbstractTestCase,
public abstract class ComparatorAbstractTestCase extends FileBasedTestCase {
/** comparator instance */
protected CompositeFileComparator comparator;
...
@Test
public void testSortArrayNull() {
assertNull(comparator.sort((File[])null)); /** LINE 96 */
}
...
}
Run Code Online (Sandbox Code Playgroud)
这是类的部分代码CompositeFileComparator,它是用类扩展的AbstractFileComparator.
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class CompositeFileComparator extends AbstractFileComparator implements Serializable { /** LINE …Run Code Online (Sandbox Code Playgroud) 我想捕获一个异常,但是如果没有捕获则会打印它将打印的相同消息(堆栈跟踪).怎么做?
我试过了
>> myfunctionwitherror
Error using myfunctionwitherror (line 3)
myerror
>> try myfunctionwitherror; catch disp(lasterror), end
Warning: This try-catch syntax will continue to work in R2007b, but may be illegal or may mean something different in future releases of MATLAB.
See MATLAB R2007a Release Notes, "Warning Generated by try-catch" for details.
MException with properties:
identifier: ''
message: 'myerror'
cause: {0×1 cell}
stack: [0×1 struct]
>> try myfunctionwitherror, catch e getReport(e), end
Warning: This try-catch syntax will continue to work in …Run Code Online (Sandbox Code Playgroud)