TRAP Command --use based on exit criteria

Hi all,
I am using the trap command in my script, and I want it to trap the signal based on the exit code the script returns.
can anybody tell me how can I use "if loop" for "trap" command.
I want to print
"terminated by user" if signal is SIGINT or 2
"failure" if signal is not 2 and not 0
"SUCCESS...!!!" if signal is 0

Thanks in advance

If there are only specific functions you know you want to fail on, you can code a function for each and eval whatever you trap within the function. Seems like too much work, because what if the error is something you never anticipated and would tip you off to the real issue (assuming you run into one)? You can't account for kill -9 -- it's going to stop your script and you're not going to get an exit code. Here's a quick way to account for singals 1-8 (you can work the rest), and by default your script is going to return 0 is it executes ok, so you can just trap 0 and 2 and I'd think the OS should be left to handle the rest...:

#!/usr/bin/ksh
# First set a trap for all signals
for x in `kill -l`
do trap "echo Failed - Signal $x" $x
#echo "Signal set to $x for $x"
done

# Change the trap for signals 0 and 2
trap 'echo "terminated by user"' 2
trap 'echo "SUCCESS"' 0

# Use a loop so it's easy to see what's happening for demo purposes
counter=0
while [ $counter -lt 8 ]
do echo "Script running"
counter=$((counter+1))
sleep 1
kill -$counter $$
done

When run, this outputs the following:
Script running
Failed - Signal HUP
Script running
terminated by user
Script running
Failed - Signal QUIT
Script running
Failed - Signal ILL
Script running
Failed - Signal TRAP
Script running
Failed - Signal ABRT
Script running
Failed - Signal EMT
Script running
Failed - Signal FPE
SUCCESS