Skip to content

Exception Handling

Austin edited this page May 5, 2017 · 1 revision

Cali-Lang has built-in exception handling. To manage exceptions, Cali uses try/catch blocks. You can also throw your own exception as well. Below is the basic syntax of a try/catch block. See the comments in the catch section that give the available functions that you can use with the exception.

try {
	// ... some code here to try
}
catch(e) {
	// ... do something with the exception
	// e.getMessage() gets the exception message.
	// e.getTrace() gets the trace as a string.
	// e.getStackTrace() gets the message and the trace as a string.
}

You can also throw your own exception. All you have to do is use the 'throw' key word and provide an expression that evaluates to a string after it.

public myFunct() {
	// ... some code here
	throw "Something went wrong!";
}

Here's a simple test to try.

class excepTest {
	public main(args) {
		try {
			tmp = 10/0;
		} catch(e) {
			c.log(e.getStackTrace());
		} 
	}
}