blog.christoffer.me

Hi, my name is Christoffer and I am an Internet addict.

2014-02-09 13:00

How to check if Checked Mode is enabled on Dartium for the Dart Language

When developing your Dart app you can tell the Dart VM to run in a Checked Mode. This is great when developing as Checked Mode will enable both assertions and type checks for your code.

You can enable this by appending the -c or --checked for the standalone vm for back-end development, or by adding --checked for the environment variables in your operating system prior to starting Dartium for front-end development.

However, there is a neat trick if you want to be notified if Dartium is launched with Checked Mode disabled.

Here is a function that throws an error if Checked Mode is disabled:

void assertCheckMode() {

    try {
        int i = '';
        throw new Exception("Check Mode is disabled!");
    } on TypeError {
    }

}

And then you can add it to your main() function:

void main() {

    assertCheckMode();

}

And if you visit your site with Dartium with Checked mode disabled, you will get the follow error in the console window:

Dartium throwing an exception

Please note, this should only be added or enabled during development, and not for production.

comments powered by Disqus

Search the site

About Christoffer

Christoffer is a software and web developer, with more than 15 years experience of the Java language, now focusing on becoming a JavaScript and Dart Ninja.

Always interested in learning new and exciting new technologies and solutions within software- and web-development and the Internet, while suffering from the classic "I can't stop thinking" syndrome.

Currently working as a JavaScript Web Developer at QlikTech, while working on his own ideas and projects via his own software company during his spare time.

Please keep in mind that any opinions expressed here are Christoffer's own opinions and does not necessarily reflect those of his employer, or any other companies, organizations, groups or individuals.

Previous posts