[ascoders] Re: AS2 Exception-Package-Problem

  • From: Florian Krüsch <florian@xxxxxxxxxx>
  • To: ascoders@xxxxxxxxxxxxx
  • Date: Fri, 12 Sep 2003 20:35:03 +0200

Hi Martin,
vielleicht funktioniert es wenn Du in den letzten Import-Block noch
"import stack" mitaufnimmst?
Florian
http://www.mx3D.com

Martin Bücker wrote:

Hallo Liste!
Ich habe zu Testzwecken in AS2 eine Klasse "DynamicStack"
geschrieben um mir die neue Syntax zu verinnerlichen.
Nun ist mir beim Testen der Klasse aufgefallen, dass trotz
korrekter import-Anweisung der catch-Block bei meiner
"EmptyStackException" nicht aufgerufen wird.
Kann mir nicht erklären warum??
Hier der Code:
------------------------------------------------------------------------
Datei: 'EmptyStackException.as' im Verzeichnis '/stack'
// Class EmptyStackException
class stack.EmptyStackException extends Error {
// Constructor
function EmptyStackException(){
message = "An 'EmptyStackException' has occured.";
name = "EmptyStackException";
}
}
Datei: 'ListNode.as' im Verzeichnis '/stack'
// Class ListNode
class stack.ListNode {
// Attributes
public var element:Object;
public var next:ListNode;
// Constructor
function ListNode(element:Object, next:ListNode){
this.element = element;
this.next = next;
}
}
Datei: 'StackInterface.as' im Verzeichnis '/stack'
// Interface StackInterface
interface stack.StackInterface {
// Methods
function push(element:Object):Void;
function pop():Object // throws EmptyStackException;
function isEmpty():Boolean;
}
Datei: 'DynamicStack.as' im Verzeichnis '/stack'
// Import classes
import stack.EmptyStackException;
import stack.ListNode;
import stack.StackInterface;
// Class Stack
class stack.DynamicStack implements StackInterface {
// Attributes
private var head:ListNode;
// Constructor
function DynamicStack() {
head = null;
}
// Methods
public function push(element:Object):Void {
head = new ListNode(element, head);
}
public function pop():Object { //throws EmptyStackException
if(isEmpty()) throw new EmptyStackException();
var element:Object = head.element;
head = head.next;
return element;
}
public function isEmpty():Boolean {
return (head == null);
} }
Datei: 'testStack.fla' im Verzeichnis '/' Frame 1:
// Import classes
import stack.DynamicStack;
import stack.EmptyStackException;
// Create Instances
var myDynStack:DynamicStack = new DynamicStack();
var hello:String = new String("%");
// Main
//myDynStack.push(new String("Hello world!"));
try{
hello = String(myDynStack.pop());
} catch(e:EmptyStackException){ // Problemzone, catch-Block wird nicht ausgeführt
trace("Error: "+e.message);
}
trace(hello);
------------------------------------------------------------------------
Der catch-Block wird halt nur aufgerufen wenn ich für meine
Exception auch das Package mitangebe, trotz explizit
angegebener import-Anweisung:
catch(e:stack.EmptyStackException){
Mache ich da irgendwas falsch?
Gruss
Martin



------------------------------------------------------ Archiv : //www.freelists.org/archives/ascoders/ Optionen : //www.freelists.org/list/ascoders ------------------------------------------------------

Other related posts: