Custom error handling |
Top Previous Next |
--catch err=function
You may add custom error handling functions which will catch script licensing errors. The error handler is a function which accepts two parameters:
error_handler( code , message )
You may use any name for this function. Also you may have different functions for different script errors. The first argument is the error code. The second one is the default error message. To set a custom error handler use --catch option for the rubyencoder command:
>rubyencoder --catch err=function myscript.rb
Where "err" is one of the predefined constants and "function" is an error handler function name.
ERR_ALL is a special value to specify "one-for-all" error handler function.
The custom error handler function should be defined before an error may occur. The best place for it is in "custom header" code as it's loaded before any license checking is done and so the error handler will be always available if defined there. But you may also define a custom error handler function in another encoded file which will be run before the script which may cause a license error. Don't put any passwords or secret data if you use a "custom header" code for defining an error handler as this code is stored unencoded.
Example:
Encode ruby script with a custom header containing definition of my_err_handler() function. Please note additional back slashes ( \ ) are used to quote special character in command line.
>rubyencoder -p "def my_err_handler(code,msg); printf \"My error handler caught error code %d with a message '%s'\\n\", code, msg; end;" --catch ERR_ALL=my_err_handler --external script.lic --projid Fg3161jd --projkey 826Gdb31 hello.rb
The encoded script will have the defined code as unencoded in the beginning:
Now a test run without the required license file:
>ruby hello.rb
|