alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (except.java)

This example Groovy source code file (except.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

exception, exception, hi, hi, hi_exception, hi_exception, io, ioexception, lo, lo_exception, lo_exception, string, text, util

The Groovy except.java source code

// $Id: except.java,v 1.1 2004-05-23 04:36:29 bfulgham Exp $
// http://www.bagley.org/~doug/shootout/
// Collection class code is from my friend Phil Chu, Thanks Phil!

import java.io.*;
import java.util.*;
import java.text.*;

class Lo_Exception extends Exception {
    int num = 0;
    public Lo_Exception(int num) {
	this.num = num;
    }
    public String toString() {
	return "Lo_Exception, num = " + this.num;
    }
}

class Hi_Exception extends Exception {
    int num = 0;
    public Hi_Exception(int num) {
	this.num = num;
    }
    public String toString() {
	return "Hi_Exception, num = " + this.num;
    }
}

public class except {
    static int Lo = 0;
    static int Hi = 0;

    public static void main(String args[]) throws IOException {
	int n = Integer.parseInt(args[0]);

	for (int i=0; i<n; i++) {
	    some_function(i);
	}
	System.out.println("Exceptions: HI=" + Hi + " / LO=" + Lo);
    }

    public static void some_function(int n) {
	try {
	    hi_function(n);
	} catch (Exception e) {
	    System.out.println("We shouldn't get here: " + e);
	}
    }

    public static void hi_function(int n) throws Hi_Exception, Lo_Exception {
	try {
	    lo_function(n);
	} catch (Hi_Exception e) {
	    Hi++;
	}
    }

    public static void lo_function(int n) throws Hi_Exception, Lo_Exception {
	try {
	    blowup(n);
	} catch (Lo_Exception e) {
	    Lo++;
	}
    }

    public static void blowup(int n) throws Hi_Exception, Lo_Exception {
	if ((n % 2) == 0) {
	    throw new Lo_Exception(n);
	} else {
	    throw new Hi_Exception(n);
	}
    }
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy except.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.