Warcraft 3 documentation
vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

ErrorMessage No New Posts Codes & Snippets

Started by
moyack

0 Members and 1 Guest are viewing this topic.

ErrorMessage
on: March 21, 2012, 03:44:14 AM
Category: String handling, Variables
Language: vJASS

Code: jass
  1. library ErrorMessage /* v1.0.1.4
  2. *************************************************************************************
  3. *
  4. *       Issue Compliant Error Messages
  5. *
  6. ************************************************************************************
  7. *
  8. *       debug function ThrowError takes boolean expression, string libraryName, string functionName, string objectName, integer objectInstance, string description returns nothing
  9. *               -       In the event of an error the game will be permanently paused
  10. *
  11. *       debug function ThrowWarning takes boolean expression, string libraryName, string functionName, string objectName, integer objectInstance, string description returns nothing
  12. *
  13. ************************************************************************************/
  14.         static if DEBUG_MODE then
  15.                 private struct Fields extends array
  16.                         static constant string COLOR_RED = "|cffff0000"
  17.                         static constant string COLOR_YELLOW = "|cffffff00"
  18.                         static string lastError = null
  19.                 endstruct
  20.                
  21.                 private function Pause takes nothing returns nothing
  22.                         call PauseGame(true)
  23.                 endfunction
  24.                
  25.                 private function ThrowMessage takes string libraryName, string functionName, string objectName, integer objectInstance, string description, string errorType, string color returns nothing
  26.                         local string str
  27.                        
  28.                         local string color_braces = "|cff66FF99"
  29.                         local string orange = "|cffff6600"
  30.                        
  31.                         set str = "->\n-> " + color_braces + "{|r " + "Library" + color_braces + "(" + orange + libraryName + color_braces + ")"
  32.                         if (objectName != null) then
  33.                                 if (objectInstance > 0) then
  34.                                         set str = str + "|r.Object" + color_braces + "(" + orange + objectName + color_braces + " (|rinstance = " + orange + I2S(objectInstance) + color_braces + ") )" + "|r." + "Method" + color_braces + "(" + orange + functionName + color_braces + ")"
  35.                                 else
  36.                                         set str = str + "|r.Object" + color_braces + "(" + orange + objectName + color_braces + ")|r." + "Method" + color_braces + "(" + orange + functionName + color_braces + ")"
  37.                                 endif
  38.                         else
  39.                                 set str = str + "|r." + "Function" + color_braces + "(" + orange + functionName + color_braces + ")"
  40.                         endif
  41.                        
  42.                         set str = str + color_braces + " }|r " + "has thrown an exception of type " + color_braces + "(" + color + errorType + color_braces + ")|r."
  43.                        
  44.                         set Fields.lastError = str + "\n->\n" + "->     " + color + description + "|r\n->"
  45.                 endfunction
  46.                
  47.                 function ThrowError takes boolean expression, string libraryName, string functionName, string objectName, integer objectInstance, string description returns nothing
  48.                         if (Fields.lastError != null) then
  49.                                 set objectInstance = 1/0
  50.                         endif
  51.                
  52.                         if (expression) then
  53.                                 call ThrowMessage(libraryName, functionName, objectName, objectInstance, description, "Error", Fields.COLOR_RED)
  54.                                 call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,Fields.lastError)
  55.                                 call TimerStart(CreateTimer(), 0, true, function Pause)
  56.                                 set objectInstance = 1/0
  57.                         endif
  58.                 endfunction
  59.  
  60.                 function ThrowWarning takes boolean expression, string libraryName, string functionName, string objectName, integer objectInstance, string description returns nothing
  61.                         if (Fields.lastError != null) then
  62.                                 set objectInstance = 1/0
  63.                         endif
  64.                
  65.                         if (expression) then
  66.                                 call ThrowMessage(libraryName, functionName, objectName, objectInstance, description, "Warning", Fields.COLOR_YELLOW)
  67.                                 call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,60000,Fields.lastError)
  68.                                 set Fields.lastError = null
  69.                         endif
  70.                 endfunction
  71.         endif
  72. endlibrary
« Last Edit: December 19, 2017, 12:54:32 AM by moyack »



 

Vivir aprendiendo.co - A place for learning stuff, in Spanish   Chaos Realm - The world of Game modders and wc3 addicts   Diplo, a gaming community   Power of Corruption, an altered melee featuring Naga and Demon. Play it now!!!   WC3JASS.com - The JASS Vault + vJASS and Zinc   Jetcraft - A Starcraft II mod   WormTastic Clan (wTc)   Warcraft RESOURCES Reforged: Modelos, mapas, proyectos y mas...