News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Exceptions

Started by Aiva, August 10, 2008, 07:08:59 PM

Previous topic - Next topic

Aiva

Exceptions are supposed to be located in excepts.hhf as said in AoA.

Quote
the system compares the exception ID against the values appearing in each of the one or more EXCEPTION clauses following the
protected code. If the current exception ID matches one of the EXCEPTION values, control continues with
the block of statements immediately following that EXCEPTION


This is taken from TRY/ENDTRY statement description. What I'm wondering about is the part in bold, I have searched for the code, which those exceptions are executing and it should be in excepts.hhf but it's not so my question is where is it?  :toothy Is it a part of compiler? if so is there any place where i can see what those exceptions look like in ASM , and one more question, if i were to define my own exception, it's code should follow immediately after definition of an exception, but I'm not sure how to define it. I assumed custom exceptions should be defined after the exceptions which are already in there, but I need an example to be sure how It should be defined.

I hope someone will help me to find out this.




Evenbit

It should say "immediately following that EXCEPTION [clause in your program]"

There is an example here:   http://webster.cs.ucr.edu/AoA/Windows/HTML/AdvCtrlStructures-1.html


program testBadInput;

#include( "stdlib.hhf" );



static

    u:      uns16;

   



begin testBadInput;



    try

   

        stdout.put( "Enter an unsigned integer:" );

        stdin.get( u );

        stdout.put( "You entered: ", u, nl );

       

      exception( ex.ConversionError )

     

        stdout.put( "Your input contained illegal characters" nl );

       

      exception( ex.ValueOutOfRange )

     

        stdout.put( "The value was too large" nl );

       

    endtry;



                   

end testBadInput;

In this example, when a "ValueOutOfRange" exception occurs, control continues to the 'stdout.put( "The value was too large" nl );' statement.

Nathan.

Randall Hyde

Quote from: Aiva on August 10, 2008, 07:08:59 PM

and one more question, if i were to define my own exception, it's code should follow immediately after definition of an exception, but I'm not sure how to define it. I assumed custom exceptions should be defined after the exceptions which are already in there, but I need an example to be sure how It should be defined.




Exception codes are simply numeric values. When I create custom exception codes I usually start with a number like 1024. The bottom line is that you must use a value greater than the exceptions already defined in excepts.hhf, but the exact value doesn't matter as long as it is unique.
hLater,
Randy Hyde