001 // Copyright (c) 2001 Hursh Jain (http://www.mollypages.org)
002 // The Molly framework is freely distributable under the terms of an
003 // MIT-style license. For details, see the molly pages web site at:
004 // http://www.mollypages.org/. Use, modify, have fun !
005
006 package fc.util;
007
008 import java.util.*;
009
010 /**
011 Handles argument {@link Checker} errors by printing the thread, time and stack trace
012 to <tt>System.err</tt>. <tt>System.err</tt> is chosen because the
013 default assertion mechanism also writes a message to that location.
014 After writing the message to <tt>System.err</tt>, a new
015 <tt>IllegalArgumentException</tt> is thrown.
016
017 @author hursh jain
018 @version 1.0
019 @date 5/30/2002
020 **/
021 public class BasicArgcheckFailHandler implements IArgcheckFailHandler
022 {
023 long id = 0;
024
025 public void handle(String msg) {
026 long myid = 0;
027 synchronized (this){
028 myid = id++;
029 }
030 String argcheckmsg = "Argcheck error [#" + myid + "] " + ((msg!=null)?msg:"");
031 System.err.println(argcheckmsg + ": " + new Date() + " " + Thread.currentThread());
032 new Exception("=== stack trace, " + argcheckmsg + "===").printStackTrace(System.err);
033 throw new IllegalArgumentException(argcheckmsg);
034 }
035 }