Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Get a String version of a stacktrace

// Get a String version of a stacktrace

    Throwable t = new Throwable();  // test code

    final Writer result = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(result);
    t.printStackTrace(printWriter);
    result.toString();

Ruby - Trace Variable Global

// Tracciare variabili Globali

trace_var:$variabileGlobale, proc{ print "variabileGlobale modificata al valore --> ", $variabileGlobale, " "}

get the name of the calling methos

caller_method_name() gets you the name of the calling method.
you could also get the line and file in which the method is called.


def caller_method_name
    parse_caller(caller(2).first).last
end

def parse_caller(at)
    if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
        file = Regexp.last_match[1]
		line = Regexp.last_match[2].to_i
		method = Regexp.last_match[3]
		[file, line, method]
	end
end

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS