I am trying to get JSON but am not able to access it.
My code is
try{
//somecode
}catch (\Exception $e){
print_r($e->message);
}
Exception is
Lin\Binance\Exceptions\Exception Object ( [message:protected] => {"code":-1111,"msg":"Precision is over the maximum defined for this asset.","_method":"POST","_url":"https:\/\/fapi.binance.com\/fapi\/v1\/ordertimestamp=1646738110000&symbol=AAVEUSDT&side=BUY&type=MARKET&quantity=0.08","_httpcode":400} [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\xampp\htdocs\Bots\bitsleaders\config\binance\vendor\linwj\binance\src\Request.php [line:protected] => 140 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\xampp\htdocs\Bots\bitsleaders\config\binance\vendor\linwj\binance\src\Api\Futures\Trade.php [line] => 49 [function] => exec [class] => Lin\Binance\Request [type] => -> [args] => Array ( ) ) [1] => Array ( [file] => C:\xampp\htdocs\Bots\bitsleaders\core.php [line] => 1985 [function] => postOrder [class] => Lin\Binance\Api\Futures\Trade [type] => -> [args] => Array ( [0] => Array ( [symbol] => AAVEUSDT [side] => BUY [type] => MARKET [quantity] => 0.08 ) ) ) [2] => Array ( [file] => C:\xampp\htdocs\Bots\bitsleaders\core.php [line] => 1936 [function] => precisionFinder [class] => dbs [type] => -> [args] => Array ( [0] => 0.082283633424218 [1] => BUY [2] => AAVEUSDT [3] => 125 [4] => 118 ) ) [3] => Array ( [file] => C:\xampp\htdocs\Bots\bitsleaders\core.php [line] => 1860 [function] => CreateFutureOrder [class] => dbs [type] => -> [args] => Array ( [0] => AAVEUSDT [1] => 132 [2] => 122 [3] => 10 [4] => long [5] => 125 [6] => 118 [7] => j4QPbksJup0txNDSnCcE ) ) [4] => Array ( [file] => C:\xampp\htdocs\Bots\bitsleaders\additional\ping2.php [line] => 95 [function] => createNewOrderFuture [class] => dbs [type] => -> [args] => Array ( [0] => AAVEUSDT [1] => 132 [2] => 122 [3] => 10 [4] => long [5] => 125 [6] => 118 [7] => j4QPbksJup0txNDSnCcE ) ) ) [previous:Exception:private] => )
The output of print_r($e->message) is
Fatal error: Uncaught Error: Cannot access protected property Lin\Binance\Exceptions\Exception::$message in C:\xampp\htdocs\Bots\bitsleaders\core.php:2018 Stack trace: #0 C:\xampp\htdocs\Bots\bitsleaders\core.php(1936): dbs->precisionFinder(0.082233541747274, 'BUY', 'AAVEUSDT', '125', '118') #1 C:\xampp\htdocs\Bots\bitsleaders\core.php(1860): dbs->CreateFutureOrder('AAVEUSDT', '132', '122', 10, 'long', '125', '118', 'j4QPbksJup0txND...') #2 C:\xampp\htdocs\Bots\bitsleaders\additional\ping2.php(95): dbs->createNewOrderFuture('AAVEUSDT', '132', '122', 10, 'long', '125', '118', 'j4QPbksJup0txND...')
CodePudding user response:
As per the manual for Exception and the error message, the message
property of the Exception
class is protected
- this means it can be accessed only within the class itself and by inheriting and parent classes (see the manual for Visibility).
Again as per that documentation you can use the getMessage function in the Exception
class to get the details of the exception:
}catch (\Exception $e){
print_r($e->getMessage());
}
P.S. I'm a bit surprised you haven't seen examples of the correct usage before, or been able to consult the documentation before this point - documentation, tutorials and examples regarding exception handling in PHP are freely available online and easy to locate.