Results 1 to 1 of 1
-
Getting Exception message into a String
Review the code below. It simply converts the printStackTrace message into a String.
Java Code:import java.io.*; public class TestStack2String { public static void main(String s[]){ try { // force an exception for demonstration purpose Class.forName("unknown").newInstance(); // or this could be changed to: // throw new Exception(); } catch (Exception e) { System.out.println(stack2string(e)); } } public static String stack2string(Exception e) { try { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); return "------\r\n" + sw.toString() + "------\r\n"; } catch(Exception e2) { return "bad stack2string"; } } }
Similar Threads
-
Please wail Message in jsp
By amar.java in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 04-02-2008, 12:29 PM -
Trouble with factory method - unhandled exception type Exception
By desmond5 in forum New To JavaReplies: 1Last Post: 03-08-2008, 06:41 PM -
simulate message box
By pablitohh in forum New To JavaReplies: 1Last Post: 12-05-2007, 04:52 PM -
Using java.util.Scanner to search for a String in a String
By Java Tip in forum Java TipReplies: 0Last Post: 11-20-2007, 04:59 PM -
How to brodcast a message in the LAN
By Alpha in forum NetworkingReplies: 1Last Post: 05-20-2007, 04:07 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks