Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Advocacy > Idea: Extend Ex...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 8 Topic 2358 of 2478
Post > Topic >>

Idea: Extend Exception mechanism with Warnings

by Daniel Jaeger <jaedan01@[EMAIL PROTECTED] > Feb 28, 2008 at 09:21 AM

Hello World

I just had a funny idea (spleen) and wonder how the Java world would
think about it: Currently, Java offers a Exception handling mechanism
with "throw" and "try-catch-finally". Exceptions always lead to an
abort of the code that throwed the exception.

Makes sense.

But maybe sometimes a developer would like to let the method that
called his code decide whether or not the exception is that bad that
the process should be aborted. This is the case if the code would
principally be able to perform despite of the exception, but the
caller might not be interested in the result anymore.

My idea is that instead of an Exception, a Warning could be "thrown".
The receiver of the Warning catches it and either says "ignore", such
that the code is resumed from where the Warning was thrown, or
"abort". In the latter case, an Exception is thrown just as in the
classical mechanism.

Here is some code example of how it could work:

void someMethod() throws IllegalStateWarning, IllegalStateException {
	// some code, then:
	warn new IllegalStateWarning("...");
}

void someClient() {
	try {
		someMethod();
	} catch (IllegalStateWarning w) {
		if (someCriterion) {
			System.out.println("Warning: " + w);
			w.ignore();
		} else {
			w.abort();
		}
	} catch (IllegalStateException e) {
		e.printStackTrace();
	}
}


--- would be equivalent to --->


void someMethod(WarningListener l) throws IllegalStateException {
	// some code, then:
	// warn new IllegalStateWarning("...")
	Warning w = new IllegalStateWarning("...")
	l.warn(w);
	if (w.aborted()) throw w.createException();
}

void someClient() {
	try {
		someMethod(new WarningListener() {
			public void warn(Warning w) {
				// catch (IllegalStateWarning w)
				if (w typeof IllegalStateWarning) {
					if (someCriterion) {
						System.out.println("Warning: " + w);
						w.ignore();
					} else {
						w.abort();
					}
				}
			}
		});
	} catch (IllegalStateException e) {
		e.printStackTrace();
	}
}

Cheers,
Daniel
 




 8 Posts in Topic:
Idea: Extend Exception mechanism with Warnings
Daniel Jaeger <jaedan0  2008-02-28 09:21:47 
Re: Idea: Extend Exception mechanism with Warnings
Daniel Pitts <newsgrou  2008-02-28 14:39:42 
Re: Idea: Extend Exception mechanism with Warnings
Daniel Jaeger <jaedan0  2008-02-29 03:14:59 
Re: Idea: Extend Exception mechanism with Warnings
"John W. Kennedy&quo  2008-02-29 13:53:12 
Re: Idea: Extend Exception mechanism with Warnings
Lothar Kimmeringer <ne  2008-03-14 22:38:27 
Re: Idea: Extend Exception mechanism with Warnings
Daniel Jaeger <jaedan0  2008-03-26 08:30:42 
Re: Idea: Extend Exception mechanism with Warnings
Daniel Pitts <newsgrou  2008-03-29 11:23:31 
Re: Idea: Extend Exception mechanism with Warnings
Daniel Jaeger <jaedan0  2008-04-01 04:53:45 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Dec 4 1:28:34 CST 2008.