Skip to content

Commit

Permalink
[improve][core] improve exception print
Browse files Browse the repository at this point in the history
  • Loading branch information
wgzhao committed May 29, 2024
1 parent 81801c0 commit 27c5761
Showing 1 changed file with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.wgzhao.addax.core.util;

import java.io.PrintWriter;
import java.io.StringWriter;

public class ExceptionTracker
{
public static final int STRING_BUFFER = 4096;

public static String trace(Throwable e) {
StringBuilder sb = new StringBuilder(STRING_BUFFER);
sb.append(e.toString()).append("\n");
StackTraceElement[] stackTrace = e.getStackTrace();
for (StackTraceElement stackTraceElement : stackTrace) {
sb.append("\t").append(stackTraceElement).append("\n");
}
return sb.toString();
StringWriter sw = new StringWriter(STRING_BUFFER);
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
return sw.toString();
}
}

0 comments on commit 27c5761

Please sign in to comment.