在這裏看到:The proper way to do exception handlingIntellij:通過IDE創建一個隨機數用作錯誤號/錯誤代碼?
說這個代碼:
function changeBookAuthor(int $id, string $newName){
if(!$newName){
throw new MyAppException('No author name was provided');
}
$book = Books::find($id);
if(!$book){
throw new MyAppException('The provided book id could not be found');
}
//..
}
我想改變這種狀況到:
function changeBookAuthor(int $id, string $newName){
if(!$newName){
throw new MyAppException('No author name was provided', <SOMEVERYRANDOMNUMBER>);
}
$book = Books::find($id);
if(!$book){
throw new MyAppException('The provided book id could not be found', <SOMEVERYRANDOMNUMBER>);
}
//..
}
的IntelliJ能幫助我在選擇隨機數?
它需要是一個靜態數字 eg 1234或543535,任何東西。但不是代碼! – Toskan
我不知道你的意思是靜態數 –
比較'random.nextInt(10)'和'2352'你能發現一個區別嗎?一個是代碼,另一個是運行時的常數 – Toskan