我想将MySQL错误从DAO函数返回给调用方。但是错误会创建一个并停止程序。因此,不会向调用方返回任何内容。DAQ 函数 如下Querypanic
var sqlquery="SELECT idfrom table where id=?"
func (mdao DbConn) Daoprocess(tz *entities.Workflowentity) ([]entities.WorkflowResponseEntity, error) {
log.Println("In side dao")
values := []entities.WorkflowResponseEntity{}
rows, err := mdao.DB.Query(sqlquery, tz.Id)
defer rows.Close()
if err != nil {
//code halts here. Nothing returns after here
return values, err
}
for rows.Next() {
value := entities.WorkflowResponseEntity{}
err:=rows.Scan(&value.Id)
if err != nil {
log.Print("Daoprocess Scan Error", err)
return values, err
}
values = append(values, value)
}
return values, nil
}
我的调用函数是这样的
values, err1 := dataAccess.Daoprocess(tz)
log.Print("\n\n INSIDE MODEL")
log.Print(err1)
if err1 != nil {
return t, false, err1, "Something Went Wrong"
}
我想处理错误并将其返回给调用方。但它造成了恐慌。如何将其传递给调用方函数?