The Silver Lining

Lessons & Learnings from a salesforce certified technical architect.

Posts Tagged ‘exception

GWT: Common Exceptions – NoClassDefFoundError

leave a comment »

This seems to be a problem that nearly everyone hits when starting with GWT. It causes confusion because the code is error free at compile time, yet throws a java.lang.NoClassDefFoundError exception at runtime. The problem is simple to correct.

The JAR-file(s) must be in the correct directory and listed in the build path.

You’ll probably have included the required library into your build path already and that’s why you’re not getting compile time errors. The additional step that is to have the JAR-file(s) that contain the required libraries be copied to your project’s war/WEB-INF/lib directory. Note that your JAR-files must exist in the root of this directory, and not in any sub-directories.

Written by Wes

May 8, 2010 at 6:29 pm

Salesforce Unit Tests & Code Coverage

with 13 comments

Unit testing *sigh*. Oh how they vex me. If they weren’t so important (and required) I’d just skip the lot, but they are and so we – champions of software development – must press on in the face of dreary complexity; we will not back down, we will not surrender, we will look that CRT/LCD screen in the pixels and say, “Untested units, you will not defeat me!”.

Diving into the thick of things, the most common question seems to be, “Why can’t I get code coverage for my entire class?!”. The trick here is to think like a runtime engine, and consider how you might journey through all possible testing paths. Now I never said it’s easy, but with a bit of practice (and 8 truck loads of patience) you’ll get there. Let’s look at some common cases. Read the rest of this entry »

Written by Wes

February 4, 2010 at 6:06 pm

Handling System.QueryException

with 5 comments

When attempting to fetch a single record from the database it is easy to run into the above exception. I’ve seen two schools of thought in dealing with this issue – mostly in the forums – and have been hoping to find a more official standpoint. Read the rest of this entry »

Written by Wes

July 9, 2009 at 1:04 pm

Throwing Custom Apex Exceptions

with 4 comments

Throwing custom exceptions is something that most Java developers expect to be able to do when working with Apex code, and indeed it is possible. It isn’t very well documented, but I managed to stumble across this solution after some experimentation.

Usually I would expect an exception to be thrown using syntax at least similar to

throw new Exception('Don\'t be a silly user.');

However this syntax will give the follow error: Type cannot be constructed: Exception

Instead you have to create a new exception class with extends the Apex Exception class

public class myException extends Exception {}

And then throw that new exception

throw new myException('Don\'t be a silly user.');

That’s just the beginning of course, you could create some pretty fancypants error handling in your custom exceptions. The world is your oyster, now all your need is some Tabasco and lime.

Written by Wes

June 11, 2009 at 8:46 am

%d bloggers like this: