exception

1367 ワード

public class TestTrack {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		testTrack();

	}

	public static void testTrack() {
		getMethodName();
	}

	public static String getMethodName() {
		String calledMethodName = "";

		try {
			//calledMethodName.charAt(1);   String.charAt()  
			throw new Exception();    // getMethodName  
		} catch (Exception e) {
			StackTraceElement[] steArray = e.getStackTrace();

			System.out.println(e.toString());
			// System.out.println(e.getCause());

			System.out
					.println("getLocalizedMessage:" + e.getLocalizedMessage());
			System.out.println("class name : " + e.getClass().getName());

		/*	for (StackTraceElement ste : steArray) {
				System.out.println(ste);
			}*/

			calledMethodName = steArray[1].toString();

			System.out.println(calledMethodName.substring(calledMethodName
					.indexOf(".") + 1, calledMethodName.indexOf("(")));

			return calledMethodName.substring(
					calledMethodName.indexOf(".") + 1, calledMethodName
							.indexOf("("));
		}
	}

}