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
006package fc.util;
007
008import java.util.*;
009
010/**
011Handles argument {@link Checker} errors by printing the thread, time and stack trace
012to <tt>System.err</tt>. <tt>System.err</tt> is chosen because the
013default assertion mechanism also writes a message to that location.
014After 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**/
021public class BasicArgcheckFailHandler implements IArgcheckFailHandler
022{
023long id = 0;
024  
025public void handle(String msg) {
026    long myid = 0;
027    synchronized (this){
028      myid = id++;
029      }
030    String argcheckmsg = Thread.currentThread() + " Argcheck error [#" + myid + "] " + ((msg!=null) ? msg : "");  
031    RuntimeException e = new IllegalArgumentException(argcheckmsg);
032    e.printStackTrace(System.err);
033    throw e;
034    }
035}