* renamed CACAO_TYPECHECK to ENABLE_VERIFIER
[cacao.git] / src / vm / exceptions.c
1 /* src/vm/exceptions.c - exception related functions
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Christian Thalinger
28
29    Changes: Edwin Steiner
30
31    $Id: exceptions.c 3807 2005-11-26 21:51:11Z edwin $
32
33 */
34
35
36 #include <string.h>
37 #include <stdarg.h>
38 #include <stdlib.h>
39
40 #include "config.h"
41
42 #include "mm/memory.h"
43 #include "native/native.h"
44 #include "native/include/java_lang_String.h"
45 #include "native/include/java_lang_Throwable.h"
46 #include "toolbox/logging.h"
47 #include "toolbox/util.h"
48 #include "vm/class.h"
49 #include "vm/exceptions.h"
50 #include "vm/global.h"
51 #include "vm/loader.h"
52 #include "vm/options.h"
53 #include "vm/stringlocal.h"
54 #include "vm/tables.h"
55 #include "vm/jit/asmpart.h"
56 #include "vm/jit/jit.h"
57
58
59 /* for raising exceptions from native methods *********************************/
60
61 #if !defined(USE_THREADS) || !defined(NATIVE_THREADS)
62 java_objectheader *_no_threads_exceptionptr = NULL;
63 #endif
64
65
66 /* init_system_exceptions ******************************************************
67
68    Load and link exceptions used in the system.
69
70 *******************************************************************************/
71
72 bool exceptions_init(void)
73 {
74         /* java/lang/Throwable */
75
76         if (!(class_java_lang_Throwable =
77                   load_class_bootstrap(utf_java_lang_Throwable)) ||
78                 !link_class(class_java_lang_Throwable))
79                 return false;
80
81
82         /* java/lang/VMThrowable */
83
84         if (!(class_java_lang_VMThrowable =
85                   load_class_bootstrap(utf_java_lang_VMThrowable)) ||
86                 !link_class(class_java_lang_VMThrowable))
87                 return false;
88
89
90         /* java/lang/Error */
91
92         if (!(class_java_lang_Error = load_class_bootstrap(utf_java_lang_Error)) ||
93                 !link_class(class_java_lang_Error))
94                 return false;
95
96         /* java/lang/NoClassDefFoundError */
97
98         if (!(class_java_lang_NoClassDefFoundError =
99                   load_class_bootstrap(utf_java_lang_NoClassDefFoundError)) ||
100                 !link_class(class_java_lang_NoClassDefFoundError))
101                 return false;
102
103         /* java/lang/LinkageError */
104
105         if (!(class_java_lang_LinkageError =
106                   load_class_bootstrap(utf_java_lang_LinkageError)) ||
107                 !link_class(class_java_lang_LinkageError))
108                 return false;
109
110         /* java/lang/NoSuchMethodError */
111
112         if (!(class_java_lang_NoSuchMethodError =
113                   load_class_bootstrap(utf_java_lang_NoSuchMethodError)) ||
114                 !link_class(class_java_lang_NoSuchMethodError))
115                 return false;
116
117         /* java/lang/OutOfMemoryError */
118
119         if (!(class_java_lang_OutOfMemoryError =
120                   load_class_bootstrap(utf_java_lang_OutOfMemoryError)) ||
121                 !link_class(class_java_lang_OutOfMemoryError))
122                 return false;
123
124
125         /* java/lang/Exception */
126
127         if (!(class_java_lang_Exception =
128                   load_class_bootstrap(utf_java_lang_Exception)) ||
129                 !link_class(class_java_lang_Exception))
130                 return false;
131
132         /* java/lang/ClassNotFoundException */
133
134         if (!(class_java_lang_ClassNotFoundException =
135                   load_class_bootstrap(utf_java_lang_ClassNotFoundException)) ||
136                 !link_class(class_java_lang_ClassNotFoundException))
137                 return false;
138
139         /* java/lang/IllegalArgumentException */
140
141         if (!(class_java_lang_IllegalArgumentException =
142                   load_class_bootstrap(utf_java_lang_IllegalArgumentException)) ||
143                 !link_class(class_java_lang_IllegalArgumentException))
144                 return false;
145
146         /* java/lang/IllegalMonitorStateException */
147
148         if (!(class_java_lang_IllegalMonitorStateException =
149                   load_class_bootstrap(utf_java_lang_IllegalMonitorStateException)) ||
150                 !link_class(class_java_lang_IllegalMonitorStateException))
151                 return false;
152
153         /* java/lang/NullPointerException */
154
155         if (!(class_java_lang_NullPointerException =
156                   load_class_bootstrap(utf_java_lang_NullPointerException)) ||
157                 !link_class(class_java_lang_NullPointerException))
158                 return false;
159
160
161         return true;
162 }
163
164
165 static void throw_exception_exit_intern(bool doexit)
166 {
167         java_objectheader *xptr;
168         classinfo *c;
169         methodinfo *pss;
170
171         xptr = *exceptionptr;
172
173         if (xptr) {
174                 /* clear exception, because we are calling jit code again */
175                 *exceptionptr = NULL;
176
177                 c = xptr->vftbl->class;
178
179                 pss = class_resolveclassmethod(c,
180                                                                            utf_printStackTrace,
181                                                                            utf_void__void,
182                                                                            class_java_lang_Object,
183                                                                            false);
184
185                 /* print the stacktrace */
186                 if (pss) {
187                         asm_calljavafunction(pss, xptr, NULL, NULL, NULL);
188
189                         /* This normally means, we are EXTREMLY out of memory or have a   */
190                         /* serious problem while printStackTrace. But may be another      */
191                         /* exception, so print it.                                        */
192
193                         if (*exceptionptr) {
194                                 java_lang_Throwable *t;
195
196                                 t = (java_lang_Throwable *) *exceptionptr;
197
198                                 fprintf(stderr, "Exception while printStackTrace(): ");
199                                 utf_fprint_classname(stderr, t->header.vftbl->class->name);
200
201                                 if (t->detailMessage) {
202                                         char *buf;
203
204                                         buf = javastring_tochar((java_objectheader *) t->detailMessage);
205                                         fprintf(stderr, ": %s", buf);
206                                         MFREE(buf, char, strlen(buf));
207                                 }
208                                         
209                                 fprintf(stderr, "\n");
210                         }
211
212                 } else {
213                         utf_fprint_classname(stderr, c->name);
214                         fprintf(stderr, ": printStackTrace()V not found!\n");
215                 }
216
217                 fflush(stderr);
218
219                 /* good bye! */
220
221                 if (doexit)
222                         exit(1);
223         }
224 }
225
226
227 void throw_exception(void)
228 {
229         throw_exception_exit_intern(false);
230 }
231
232
233 void throw_exception_exit(void)
234 {
235         throw_exception_exit_intern(true);
236 }
237
238
239 void throw_main_exception(void)
240 {
241         fprintf(stderr, "Exception in thread \"main\" ");
242         fflush(stderr);
243
244         throw_exception_exit_intern(false);
245 }
246
247
248 void throw_main_exception_exit(void)
249 {
250         fprintf(stderr, "Exception in thread \"main\" ");
251         fflush(stderr);
252
253         throw_exception_exit_intern(true);
254 }
255
256
257 void throw_cacao_exception_exit(const char *exception, const char *message, ...)
258 {
259         s4 i;
260         char *tmp;
261         s4 len;
262         va_list ap;
263
264         len = strlen(exception);
265         tmp = MNEW(char, len + 1);
266         strncpy(tmp, exception, len);
267         tmp[len] = '\0';
268
269         /* convert to classname */
270
271         for (i = len - 1; i >= 0; i--)
272                 if (tmp[i] == '/') tmp[i] = '.';
273
274         fprintf(stderr, "Exception in thread \"main\" %s", tmp);
275
276         MFREE(tmp, char, len);
277
278         if (strlen(message) > 0) {
279                 fprintf(stderr, ": ");
280
281                 va_start(ap, message);
282                 vfprintf(stderr, message, ap);
283                 va_end(ap);
284         }
285
286         fprintf(stderr, "\n");
287         fflush(stderr);
288
289         /* good bye! */
290
291         exit(1);
292 }
293
294
295 /* exceptions_throw_outofmemory_exit *******************************************
296
297    Just print an: java.lang.InternalError: Out of memory
298
299 *******************************************************************************/
300
301 void exceptions_throw_outofmemory_exit(void)
302 {
303         throw_cacao_exception_exit(string_java_lang_InternalError,
304                                                            "Out of memory");
305 }
306
307
308 /* new_exception ***************************************************************
309
310    Creates an exception object with the given name and initalizes it.
311
312 *******************************************************************************/
313
314 java_objectheader *new_exception(const char *classname)
315 {
316         java_objectheader *o;
317         classinfo         *c;
318
319         if (!(c = load_class_bootstrap(utf_new_char(classname))))
320                 return *exceptionptr;
321
322         o = native_new_and_init(c);
323
324         if (!o)
325                 return *exceptionptr;
326
327         return o;
328 }
329
330
331 /* new_exception_message *******************************************************
332
333    Creates an exception object with the given name and initalizes it
334    with the given char message.
335
336 *******************************************************************************/
337
338 java_objectheader *new_exception_message(const char *classname,
339                                                                                  const char *message)
340 {
341         java_objectheader *o;
342         classinfo         *c;
343    
344         if (!(c = load_class_bootstrap(utf_new_char(classname))))
345                 return *exceptionptr;
346
347         o = native_new_and_init_string(c, javastring_new_char(message));
348
349         if (!o)
350                 return *exceptionptr;
351
352         return o;
353 }
354
355
356 /* new_exception_throwable *****************************************************
357
358    Creates an exception object with the given name and initalizes it
359    with the given java/lang/Throwable exception.
360
361 *******************************************************************************/
362
363 java_objectheader *new_exception_throwable(const char *classname,
364                                                                                    java_lang_Throwable *throwable)
365 {
366         java_objectheader *o;
367         classinfo         *c;
368    
369         if (!(c = load_class_bootstrap(utf_new_char(classname))))
370                 return *exceptionptr;
371
372         o = native_new_and_init_throwable(c, throwable);
373
374         if (!o)
375                 return *exceptionptr;
376
377         return o;
378 }
379
380
381 /* new_exception_utfmessage ****************************************************
382
383    Creates an exception object with the given name and initalizes it
384    with the given utf message.
385
386 *******************************************************************************/
387
388 java_objectheader *new_exception_utfmessage(const char *classname, utf *message)
389 {
390         java_objectheader *o;
391         classinfo         *c;
392    
393         if (!(c = load_class_bootstrap(utf_new_char(classname))))
394                 return *exceptionptr;
395
396         o = native_new_and_init_string(c, javastring_new(message));
397
398         if (!o)
399                 return *exceptionptr;
400
401         return o;
402 }
403
404
405 /* new_exception_javastring ****************************************************
406
407    Creates an exception object with the given name and initalizes it
408    with the given java/lang/String message.
409
410 *******************************************************************************/
411
412 java_objectheader *new_exception_javastring(const char *classname,
413                                                                                         java_lang_String *message)
414 {
415         java_objectheader *o;
416         classinfo         *c;
417    
418         if (!(c = load_class_bootstrap(utf_new_char(classname))))
419                 return *exceptionptr;
420
421         o = native_new_and_init_string(c, message);
422
423         if (!o)
424                 return *exceptionptr;
425
426         return o;
427 }
428
429
430 /* new_exception_int ***********************************************************
431
432    Creates an exception object with the given name and initalizes it
433    with the given int value.
434
435 *******************************************************************************/
436
437 java_objectheader *new_exception_int(const char *classname, s4 i)
438 {
439         java_objectheader *o;
440         classinfo         *c;
441    
442         if (!(c = load_class_bootstrap(utf_new_char(classname))))
443                 return *exceptionptr;
444
445         o = native_new_and_init_int(c, i);
446
447         if (!o)
448                 return *exceptionptr;
449
450         return o;
451 }
452
453
454 /* new_classformaterror ********************************************************
455
456    generates a java.lang.ClassFormatError for the classloader
457
458 *******************************************************************************/
459
460 java_objectheader *new_classformaterror(classinfo *c, const char *message, ...)
461 {
462         java_objectheader *o;
463         char              *msg;
464         s4                 msglen;
465         va_list            ap;
466
467         /* calculate message length */
468
469         msglen = 0;
470
471         if (c)
472                 msglen += utf_strlen(c->name) + strlen(" (");
473
474         va_start(ap, message);
475         msglen += get_variable_message_length(message, ap);
476         va_end(ap);
477
478         if (c)
479                 msglen += strlen(")");
480
481         msglen += strlen("0");
482
483         /* allocate a buffer */
484
485         msg = MNEW(char, msglen);
486
487         /* print message into allocated buffer */
488
489         if (c) {
490                 utf_sprint_classname(msg, c->name);
491                 strcat(msg, " (");
492         }
493
494         va_start(ap, message);
495         vsprintf(msg + strlen(msg), message, ap);
496         va_end(ap);
497
498         if (c)
499                 strcat(msg, ")");
500
501         o = new_exception_message(string_java_lang_ClassFormatError, msg);
502
503         MFREE(msg, char, msglen);
504
505         return o;
506 }
507
508
509 /* new_classnotfoundexception **************************************************
510
511    Generates a java.lang.ClassNotFoundException for the classloader.
512
513 *******************************************************************************/
514
515 java_objectheader *new_classnotfoundexception(utf *name)
516 {
517         java_objectheader *o;
518
519         o = native_new_and_init_string(class_java_lang_ClassNotFoundException,
520                                                                    javastring_new(name));
521
522         if (!o)
523                 return *exceptionptr;
524
525         return o;
526 }
527
528
529 /* new_noclassdeffounderror ****************************************************
530
531    Generates a java.lang.NoClassDefFoundError
532
533 *******************************************************************************/
534
535 java_objectheader *new_noclassdeffounderror(utf *name)
536 {
537         java_objectheader *o;
538
539         o = native_new_and_init_string(class_java_lang_NoClassDefFoundError,
540                                                                    javastring_new(name));
541
542         if (!o)
543                 return *exceptionptr;
544
545         return o;
546 }
547
548
549 /* classnotfoundexception_to_noclassdeffounderror ******************************
550
551    Check the *exceptionptr for a ClassNotFoundException. If it is one,
552    convert it to a NoClassDefFoundError.
553
554 *******************************************************************************/
555
556 void classnotfoundexception_to_noclassdeffounderror(void)
557 {
558         java_objectheader *xptr;
559         java_objectheader *cause;
560
561         /* get the cause */
562
563         cause = *exceptionptr;
564
565         /* convert ClassNotFoundException's to NoClassDefFoundError's */
566
567         if (builtin_instanceof(cause, class_java_lang_ClassNotFoundException)) {
568                 /* clear exception, because we are calling jit code again */
569
570                 *exceptionptr = NULL;
571
572                 /* create new error */
573
574                 xptr =
575                         new_exception_javastring(string_java_lang_NoClassDefFoundError,
576                                         ((java_lang_Throwable *) cause)->detailMessage);
577
578                 /* we had an exception while creating the error */
579
580                 if (*exceptionptr)
581                         return;
582
583                 /* set new exception */
584
585                 *exceptionptr = xptr;
586         }
587 }
588
589
590 /* new_internalerror ***********************************************************
591
592    Generates a java.lang.InternalError for the VM.
593
594 *******************************************************************************/
595
596 java_objectheader *new_internalerror(const char *message, ...)
597 {
598         java_objectheader *o;
599         va_list            ap;
600         char              *msg;
601         s4                 msglen;
602
603         /* calculate exception message length */
604
605         va_start(ap, message);
606         msglen = get_variable_message_length(message, ap);
607         va_end(ap);
608
609         /* allocate memory */
610
611         msg = MNEW(char, msglen);
612
613         /* generate message */
614
615         va_start(ap, message);
616         vsprintf(msg, message, ap);
617         va_end(ap);
618
619         /* create exception object */
620
621         o = new_exception_message(string_java_lang_InternalError, msg);
622
623         /* free memory */
624
625         MFREE(msg, char, msglen);
626
627         return o;
628 }
629
630
631 /* exceptions_new_linkageerror *************************************************
632
633    Generates a java.lang.LinkageError with an error message.
634    If c != NULL, the name of c is appended to the error message.
635
636 *******************************************************************************/
637
638 java_objectheader *exceptions_new_linkageerror(const char *message,
639                                                                                            classinfo *c)
640 {
641         java_objectheader *o;
642         char              *msg;
643         s4                 msglen;
644
645         /* calculate exception message length */
646
647         msglen = strlen(message) + 1;
648         if (c) {
649                 msglen += utf_strlen(c->name);
650         }
651                 
652         /* allocate memory */
653
654         msg = MNEW(char, msglen);
655
656         /* generate message */
657
658         strcpy(msg,message);
659         if (c) {
660                 utf_strcat(msg, c->name);
661         }
662
663         o = native_new_and_init_string(class_java_lang_LinkageError,
664                                                                    javastring_new_char(msg));
665
666         /* free memory */
667
668         MFREE(msg, char, msglen);
669
670         return o;
671 }
672
673
674 /* exceptions_new_nosuchmethoderror ********************************************
675
676    Generates a java.lang.NoSuchMethodError with an error message.
677
678 *******************************************************************************/
679
680 java_objectheader *exceptions_new_nosuchmethoderror(classinfo *c,
681                                                                                                         utf *name, utf *desc)
682 {
683         java_objectheader *o;
684         char              *msg;
685         s4                 msglen;
686
687         /* calculate exception message length */
688
689         msglen = utf_strlen(c->name) + strlen(".") + utf_strlen(name) +
690                 utf_strlen(desc) + strlen("0");
691
692         /* allocate memory */
693
694         msg = MNEW(char, msglen);
695
696         /* generate message */
697
698         utf_sprint(msg, c->name);
699         strcat(msg, ".");
700         utf_strcat(msg, name);
701         utf_strcat(msg, desc);
702
703         o = native_new_and_init_string(class_java_lang_NoSuchMethodError,
704                                                                    javastring_new_char(msg));
705
706         /* free memory */
707
708         MFREE(msg, char, msglen);
709
710         return o;
711 }
712
713
714 /* new_unsupportedclassversionerror ********************************************
715
716    generates a java.lang.UnsupportedClassVersionError for the classloader
717
718 *******************************************************************************/
719
720 java_objectheader *new_unsupportedclassversionerror(classinfo *c, const char *message, ...)
721 {
722         java_objectheader *o;
723         va_list            ap;
724         char              *msg;
725     s4                 msglen;
726
727         /* calculate exception message length */
728
729         msglen = utf_strlen(c->name) + strlen(" (") + strlen(")") + strlen("0");
730
731         va_start(ap, message);
732         msglen += get_variable_message_length(message, ap);
733         va_end(ap);
734
735         /* allocate memory */
736
737         msg = MNEW(char, msglen);
738
739         /* generate message */
740
741         utf_sprint_classname(msg, c->name);
742         strcat(msg, " (");
743
744         va_start(ap, message);
745         vsprintf(msg + strlen(msg), message, ap);
746         va_end(ap);
747
748         strcat(msg, ")");
749
750         /* create exception object */
751
752         o = new_exception_message(string_java_lang_UnsupportedClassVersionError,
753                                                           msg);
754
755         /* free memory */
756
757         MFREE(msg, char, msglen);
758
759         return o;
760 }
761
762
763 /* new_verifyerror *************************************************************
764
765    generates a java.lang.VerifyError for the jit compiler
766
767 *******************************************************************************/
768
769 java_objectheader *new_verifyerror(methodinfo *m, const char *message, ...)
770 {
771         java_objectheader *o;
772         va_list            ap;
773         char              *msg;
774         s4                 msglen;
775
776         useinlining = false; /* at least until sure inlining works with exceptions*/
777
778         /* calculate exception message length */
779
780         msglen = 0;
781
782         if (m)
783                 msglen = strlen("(class: ") + utf_strlen(m->class->name) +
784                         strlen(", method: ") + utf_strlen(m->name) +
785                         strlen(" signature: ") + utf_strlen(m->descriptor) +
786                         strlen(") ") + strlen("0");
787
788         va_start(ap, message);
789         msglen += get_variable_message_length(message, ap);
790         va_end(ap);
791
792         /* allocate memory */
793
794         msg = MNEW(char, msglen);
795
796         /* generate message */
797
798         if (m) {
799                 strcpy(msg, "(class: ");
800                 utf_strcat(msg, m->class->name);
801                 strcat(msg, ", method: ");
802                 utf_strcat(msg, m->name);
803                 strcat(msg, " signature: ");
804                 utf_strcat(msg, m->descriptor);
805                 strcat(msg, ") ");
806         }
807
808         va_start(ap, message);
809         vsprintf(msg + strlen(msg), message, ap);
810         va_end(ap);
811
812         /* create exception object */
813
814         o = new_exception_message(string_java_lang_VerifyError, msg);
815
816         /* free memory */
817
818         MFREE(msg, char, msglen);
819
820         return o;
821 }
822
823
824 /* new_arithmeticexception *****************************************************
825
826    Generates a java.lang.ArithmeticException for the jit compiler.
827
828 *******************************************************************************/
829
830 java_objectheader *new_arithmeticexception(void)
831 {
832         java_objectheader *e;
833
834         e = new_exception_message(string_java_lang_ArithmeticException,
835                                                           string_java_lang_ArithmeticException_message);
836
837         if (!e)
838                 return *exceptionptr;
839
840         return e;
841 }
842
843
844 /* new_arrayindexoutofboundsexception ******************************************
845
846    Generates a java.lang.ArrayIndexOutOfBoundsException for the JIT
847    compiler.
848
849 *******************************************************************************/
850
851 java_objectheader *new_arrayindexoutofboundsexception(s4 index)
852 {
853         java_objectheader *e;
854         methodinfo *m;
855         java_lang_String *s;
856
857         /* convert the index into a String, like Sun does */
858
859         m = class_resolveclassmethod(class_java_lang_String,
860                                                                  utf_new_char("valueOf"),
861                                                                  utf_new_char("(I)Ljava/lang/String;"),
862                                                                  class_java_lang_Object,
863                                                                  true);
864
865         if (!m)
866                 return *exceptionptr;
867
868         s = (java_lang_String *) asm_calljavafunction(m,
869                                                                                                   (void *) (ptrint) index,
870                                                                                                   NULL,
871                                                                                                   NULL,
872                                                                                                   NULL);
873
874         if (!s)
875                 return *exceptionptr;
876
877         e = new_exception_javastring(string_java_lang_ArrayIndexOutOfBoundsException,
878                                                                  s);
879
880         if (!e)
881                 return *exceptionptr;
882
883         return e;
884 }
885
886
887 /* new_arraystoreexception *****************************************************
888
889    generates a java.lang.ArrayStoreException for the jit compiler
890
891 *******************************************************************************/
892
893 java_objectheader *new_arraystoreexception(void)
894 {
895         java_objectheader *e;
896
897         e = new_exception(string_java_lang_ArrayStoreException);
898 /*      e = native_new_and_init(class_java_lang_ArrayStoreException); */
899
900         if (!e)
901                 return *exceptionptr;
902
903         return e;
904 }
905
906
907 /* new_classcastexception ******************************************************
908
909    generates a java.lang.ClassCastException for the jit compiler
910
911 *******************************************************************************/
912
913 java_objectheader *new_classcastexception(void)
914 {
915         java_objectheader *e;
916
917         e = new_exception(string_java_lang_ClassCastException);
918
919         if (!e)
920                 return *exceptionptr;
921
922         return e;
923 }
924
925
926 /* new_illegalargumentexception ************************************************
927
928    Generates a java.lang.IllegalArgumentException for the VM system.
929
930 *******************************************************************************/
931
932 java_objectheader *new_illegalargumentexception(void)
933 {
934         java_objectheader *e;
935
936         if (!(e = native_new_and_init(class_java_lang_IllegalArgumentException)))
937                 return *exceptionptr;
938
939         return e;
940 }
941
942
943 /* new_illegalmonitorstateexception ********************************************
944
945    Generates a java.lang.IllegalMonitorStateException for the VM
946    thread system.
947
948 *******************************************************************************/
949
950 java_objectheader *new_illegalmonitorstateexception(void)
951 {
952         java_objectheader *e;
953
954         if (!(e = native_new_and_init(class_java_lang_IllegalMonitorStateException)))
955                 return *exceptionptr;
956
957         return e;
958 }
959
960
961 /* new_negativearraysizeexception **********************************************
962
963    generates a java.lang.NegativeArraySizeException for the jit compiler
964
965 *******************************************************************************/
966
967 java_objectheader *new_negativearraysizeexception(void)
968 {
969         java_objectheader *e;
970
971         e = new_exception(string_java_lang_NegativeArraySizeException);
972
973         if (!e)
974                 return *exceptionptr;
975
976         return e;
977 }
978
979
980 /* new_nullpointerexception ****************************************************
981
982    generates a java.lang.NullPointerException for the jit compiler
983
984 *******************************************************************************/
985
986 java_objectheader *new_nullpointerexception(void)
987 {
988         java_objectheader *e;
989
990         e = native_new_and_init(class_java_lang_NullPointerException);
991
992         if (!e)
993                 return *exceptionptr;
994
995         return e;
996 }
997
998
999 /* exceptions_print_exception **************************************************
1000
1001    Prints an exception, the detail message and the cause, if
1002    available, with CACAO internal functions to stdout.
1003
1004 *******************************************************************************/
1005
1006 void exceptions_print_exception(java_objectheader *xptr)
1007 {
1008         java_lang_Throwable   *t;
1009         java_lang_Throwable   *cause;
1010         utf                   *u;
1011
1012         t = (java_lang_Throwable *) xptr;
1013         cause = t->cause;
1014
1015         /* print the root exception */
1016
1017         utf_display_classname(t->header.vftbl->class->name);
1018
1019         if (t->detailMessage) {
1020                 u = javastring_toutf(t->detailMessage, false);
1021
1022                 printf(": ");
1023                 utf_display(u);
1024         }
1025
1026         putc('\n', stdout);
1027
1028         /* print the cause if available */
1029
1030         if (cause && (cause != t)) {
1031                 printf("Caused by: ");
1032                 utf_display_classname(cause->header.vftbl->class->name);
1033
1034                 if (cause->detailMessage) {
1035                         u = javastring_toutf(cause->detailMessage, false);
1036
1037                         printf(": ");
1038                         utf_display(u);
1039                 }
1040
1041                 putc('\n', stdout);
1042         }
1043 }
1044
1045
1046 /*
1047  * These are local overrides for various environment variables in Emacs.
1048  * Please do not remove this and leave it at the end of the file, where
1049  * Emacs will automagically detect them.
1050  * ---------------------------------------------------------------------
1051  * Local variables:
1052  * mode: c
1053  * indent-tabs-mode: t
1054  * c-basic-offset: 4
1055  * tab-width: 4
1056  * End:
1057  */