Were this a controversy between the mother of the child and the putative father, as to which had the better right to the custody and guardianship of the child, as the relator’s counsel seems to have supposed it to be, there could be no doubt that the decision of the county judge was erroneous. As against the mother of a bastard child, the putative father has no legal right to its custody. The mother, as its natural guardian, is bound to maintain it, and is entitled to the control of it. It is only by provision of statute, and the inter*368vention of public officers, that the father can be compelled to support it. (3 Kent's Com. 5th ed. 216.)
But the difficulty with the relator’s case is, that this is not a question to be determined upon habeas corpus. This writ is, by eminence, the writ of liberty. Its office is, to inquire into the ground upon which any person is restrained of his liberty, and, when it is found that the restraint is illegal, to deliver him from such illegal restraint. Ordinarily, this end is attained by allowing the party improperly detained the free exercise of his volition. But in the case of a child, too young to be capable of determining for itself, the court or officer assumes to determine for it. In making such election for the child, its welfare is chiefly, if not exclusively, to be had in view. The rights of parental authority are to be regarded no farther than they are consistent with the best good of the child. The tribunal before which it is brought, is to do what it may suppose the child, in the exercise of a proper judgment, and looking to its own benefit, would do. In the matter of the McDowells, (8 John, 328,) it was held, upon the authority of Lord Mansfield in Rex v. Delaval, (3 Burr. 1434,) that, upon habeas corpus all the court was bound to do, ex debito justifico, was to set the infant free from improper restraint; that'whether it would deliver it over to any body, must be left to its discretion. . In that case two boys, one eleven, the other eight years old, were brought before the court upon writs of habeas corpus, issued upon the application of the father, to members of the society of Shakers, with whom the children were living. The court said all they were required to do upon that writ, was to declare that the infants were at liberty to go where they pleased, and upon being satisfied that they desired to return to the Shakers, an officer was directed to protect them in their return. So in the matter of Waldron, (13 Wend. 418,) the court, being satisfied that it would be more for the benefit of the infant to remain with its grandfather, to whom the habeas corpus had been issued, refused to direct it to be delivered to its father. The court said it was a matter resting in the sound discretion of the court, and not a matter of right which the father could claim at their *369hands. The same principle is recognized by Justice Bronson in Mercein v. The People, (25 Wend. 73.)
I admit that this discretion is not to be arbitrarily exercised. Nor are the rights of the parent to be wholly disregarded. While the court is bound to give such direction, in relation to the custody of the child, as in its conscience it believes will be most for its interest; it is also bound, I think, other things being equal, to prefer the claim of the parent, as against third persons, and the father as against the mother. In this case, although a matter addressed to the discretion of the judge, if it had appeared that the relator had possessed the capacity and means of maintaining and educating the child as well as its grandfather, who had received it into his family, I think a judicious exercise of his power would have required the judge to d eh ver the child into the custody of its mother. But such a state of facts was not presented. No one, upon the evidence as it appeared before the judge, could hesitate to believe that the child, if capable of deciding for itself, would have preferred to remain where it was, rather than return to its mother. If it remained, it had the prospect of a home, and a comfortable support. If it returned, it would have little else to expect, but a precarious living for the present, and ignorance, and idleness, perhaps degradation and vice for the future. I am, therefore, entirely satisfied with the determination of the county judge to leave the child with its grandfather
But whether the judge exercised his discretion wisely or not, is a question which does not admit of review. Even though he may have been guilty of a flagrant abuse of his discretion, yet so far as his decision rested in mere discretion, this court has no right to interfere. No rule is now better settled than that error is not predicable of any matter resting in mere discretion. It is true the statute authorizes the removal of all proceedings, commenced under the article relating to writs of habeas corpus, by certiorari, into the supreme court, “ there to be examined and corrected.” But the review here provided, like all other-cases of review upon error, must be confined to matters of law. If there has been no error in law, the proceedings can not be *370“ corrected,” however improperly the tribunal below may have exercised its power. (United States v. Wyngall, 5 Hill, 16.) Although the chancellor, in the oral opinion delivered by him in the case of Mercein v. The People, (25 Wend. 97,) is reported to have used language from which it might be inferred that it was his opinion that the statute had conferred upon this court the power of reviewing and correcting all decisions of the inferior tribunal, under the habeas corpus act, yet there is nothing in what that learned jurist is reported to have said on that occasion, from which it is necessarily to be understood that such was his understanding of the statute. I agree with him that the certiorari which the statute gives for the removal of the proceedings, is not a mere common law certiorari, limiting the court, in its review, to the single question of jurisdiction; and farther, that the statute contemplates a review upon the merits, when the proceedings have been removed, so far as the legal rights of the parties are involved, and if any error has happened in respect to such legal rights, that they should be “ corrected” by the court of review. Beyond that I do not think the chancellor himself intended to go. But in any view that 'may be taken of this case I think the proceedings of the county judge should be affirmed.
Proceedings affirmed.