# Try...catch for getQualifiedClassName

**URL:** <https://forum.kirupa.com/t/try-catch-for-getqualifiedclassname/269170>\
**Category:** Uncategorized\
**Created:** [August 23, 2008, 9:48pm UTC](https://forum.kirupa.com/t/try-catch-for-getqualifiedclassname/269170 "2008-08-23T21:48:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bootiteq](https://avatars.discourse-cdn.com/v4/letter/b/eb9ed0/32.png) [@bootiteq](https://forum.kirupa.com/u/bootiteq)\
**Post date:** [August 23, 2008, 9:48pm UTC](https://forum.kirupa.com/t/try-catch-for-getqualifiedclassname/269170/1 "2008-08-23T21:48:53Z")

</div>

How do I check if a class exists? and handle the error if it doesn’t?

if the class exists the code below traces  
// no Error  
// Finally!

However if it doesnt exist i get a compiler error  
// 1120: Access of undefined property cm\_button\_bg\_g

I was leaad to believe the try catch statement should handle the compiler error… Am I going about this the wrong way?

```auto

try {
   getQualifiedClassName(cm_button_bg_g) == "cm_button_bg_g";
   trace("no Error ");
} catch(error:Error) {
   trace("Error catch: " + error);
} finally {
   trace("Finally!");
}

```

Any help would be greatly appreciated 🙂

---

<div class="post-metadata">

**Author:** ![wvxvw](https://avatars.discourse-cdn.com/v4/letter/w/a9a28c/32.png) [@wvxvw](https://forum.kirupa.com/u/wvxvw)\
**Post date:** [August 23, 2008, 10:44pm UTC](https://forum.kirupa.com/t/try-catch-for-getqualifiedclassname/269170/2 "2008-08-23T22:44:03Z")

</div>

getQualifiedClassName() doesn’t throw any errors. The error you’re getting isn’t a run-time error, it’s compile-time… Sure, if there’s no cm\_button\_bg\_g variable it won’t compile…  
Did you mean getDefinitionByName()? it may throw ReferenceError.

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [August 23, 2008, 10:49pm UTC](https://forum.kirupa.com/t/try-catch-for-getqualifiedclassname/269170/3 "2008-08-23T22:49:14Z")

</div>

getQualifiedClassName will return the classname of the object you pass to it. In this case you want to check if a class is actually existing right?

Try this on for size;

```auto

var classExists:Boolean = true;
var classNameToTest:String = "flash.display.Sprite";

try 
{
   var k = getDefinitionByName(classNameToTest);
} 
catch(e:Error) 
{
   trace("Statement threw an error: " + e);
   classExists = false;
} 

classExists ? trace("Your class exists") : trace("Your class doesn't exist");

```

---

<div class="post-metadata">

**Author:** ![bootiteq](https://avatars.discourse-cdn.com/v4/letter/b/eb9ed0/32.png) [@bootiteq](https://forum.kirupa.com/u/bootiteq)\
**Post date:** [August 23, 2008, 11:03pm UTC](https://forum.kirupa.com/t/try-catch-for-getqualifiedclassname/269170/4 "2008-08-23T23:03:03Z")

</div>

Oh man, words can not describe how helpful those posts are! works a treat now.

I also know to look for the **throws** heading in help when using try catch now.

thanks again 🙂

---

<div class="post-metadata">

**Author:** ![sekasi](https://avatars.discourse-cdn.com/v4/letter/s/5f8ce5/32.png) [@sekasi](https://forum.kirupa.com/u/sekasi)\
**Post date:** [August 24, 2008, 1:04am UTC](https://forum.kirupa.com/t/try-catch-for-getqualifiedclassname/269170/5 "2008-08-24T01:04:14Z")

</div>

You’re welcome 😃
